Advertising
- mediamouse
- Thursday, February 28th, 2008 at 5:20:11pm UTC
- #!/bin/bash
- #
- #
- # simple script to make amarok to work with some of my media buttons on the mouse.
- # this script i wrote to work with xbindkeys
- #
- # Needed stuff:
- # xbindkeys
- # evdev module compiled for Xorg "already bult in kubuntu's xorg server"
- # kernel usbstuff- "evdev" module
- #
- # cat /proc/bus/input/devices
- # looks something like:
- #
- # I: Bus=0003 Vendor=046d Product=c50e Version=0111
- # N: Name="Logitech USB RECEIVER"
- # P: Phys=usb-0000:00:0b.0-4/input0
- # S: Sysfs=/class/input/input4
- # U: Uniq=
- # H: Handlers=mouse0 event1 ts0
- # B: EV=20007
- # B: KEY=ffff0000 0 0 0 0 0 0 0 0
- # B: REL=143
- # B: LED=ff00
- #
- # Find your mouse event. usaly event0 or event1
- # Now edit /etc/X11/xorg.conf and replace
- #
- # Driver "mouse"
- # with
- # Driver "evdev"
- # and
- # Option "Device" "/dev/psaux" #mice or whatever whats written there..
- # with
- # Option "Device" "/dev/input/event1"
- #
- # Now use "xev" to find the button numbers.
- # then make a new file called ".xbindkeysrc" in your home dir,
- #
- # the file may look something like.
- #
- # ############# .XBINDKEYSRC #############
- #
- # "/usr/bin/mediamouse start"
- # b:17 + Release
- #
- # "/usr/bin/mediamouse stop"
- # b:10 + Release
- #
- # "/usr/bin/mediamouse next"
- # b:15 + Release
- #
- # "/usr/bin/mediamouse prev"
- # b:16 + Release
- #
- # "/usr/bin/mediamouse up"
- # b:13 + Release
- #
- # "/usr/bin/mediamouse down"
- # b:14 + Release
- #
- # #########################################
- #
- # copy the script to /usr/bin or change the path in .xbindkeysrc to where the script it located.
- # also run "sudo chmod 755 mediamouse"
- # this script is GPL and made by nuxil.
- #
- ARG=$1
- function start()
- {
- ## play/pause button toggle function.
- ## if no amarok found running. start it up and play song from playlist.
- if [[ ! `pgrep amarokapp` ]]
- ## start it up and sleep 3 secs. give it some time to load up
- then exec amarokapp & sleep 3
- exec dcop amarok player play
- ## if amarok is running.then we need a toogle function to toggle play pause..
- else
- ## if a song is playing then pause.
- if [[ `dcop amarok player status` -eq "2" ]]
- then exec dcop amarok player pause
- else exec dcop amarok player play
- fi
- fi
- }
- function stop()
- {
- if [[ `pgrep amarokapp` ]]
- then exec dcop amarok player stop
- fi
- }
- function next()
- {
- if [[ `pgrep amarokapp` ]]
- then exec dcop amarok player next
- fi
- }
- function prev()
- {
- if [[ `pgrep amarokapp` ]]
- then exec dcop amarok player prev
- fi
- }
- function up()
- {
- if [[ `pgrep amarokapp` ]]
- then exec dcop amarok player volumeUp
- fi
- }
- function down()
- {
- if [[ `pgrep amarokapp` ]]
- then exec dcop amarok player volumeDown
- fi
- }
- ## forward 5 sec's
- function pfwd()
- {
- if [[ `pgrep amarokapp` ]]
- then CT=`dcop amarok player currentTime`
- # current minutte(s) time
- CTM=`echo ${CT} | tr ":" " " | awk '{print $1}'`
- # current second(s) time
- CTS=`echo ${CT} | tr ":" " " | awk '{print $2}'`
- # 01, 02 so one. sometimes errors "bash outputs errors." . so we remove the 1st position of the string
- # when its under 10, and the lenght of the string to 1 position only
- if [[ ${CTS:0:1} == "0" ]]
- then CTS=${CTS:1:1}
- fi
- # make minutes and seconds to seconds only and forward 5 secs
- MTS=$((${CTM:0} * 60))
- ST=$((${MTS} + ${CTS}))
- FWD=$(($ST + 5))
- exec dcop amarok player seek $FWD
- fi
- }
- ## backwards 5 sec-. and under 10 sec playtime. 2 sec back
- function pbwd()
- {
- if [[ `pgrep amarokapp` ]]
- then CT=`dcop amarok player currentTime`
- # current minutte(s) time
- CTM=`echo ${CT} | tr ":" " " | awk '{print $1}'`
- # current second(s) time
- CTS=`echo ${CT} | tr ":" " " | awk '{print $2}'`
- # make minutes and seconds to seconds only
- MTS=$((${CTM:0} * 60))
- ST=$((${MTS} + ${CTS}))
- # 01, 02 so one. sometimes errors "bash outputs errors." . so we remove the 1st position of the string
- # when its under 10, and the lenght of the string to 1 position only
- if [[ ${CTS:0:1} == "0" ]]
- then CTS=${CTS:1:1}
- BWD=$(($ST - 2))
- exec dcop amarok player seek $BWD
- # over 10 means over 10 sec. then we increase time backwards to -5
- else CTS=${CTS:0}
- BWD=$(($ST - 5))
- exec dcop amarok player seek $BWD
- fi
- fi
- }
- case $ARG in start)
- start
- ;;
- stop)
- stop
- ;;
- next)
- next
- ;;
- prev)
- prev
- ;;
- up)
- up
- ;;
- down)
- down
- ;;
- pfwd)
- pfwd
- ;;
- pbwd)
- pbwd
- ;;
- *)
- exit 0
- ;;
- esac
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will not expire by default. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.