Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate

Advertising

Miscellany
Saturday, March 1st, 2008 at 5:52:06pm UTC 

  1. #!/bin/bash
  2.  
  3. #
  4. #
  5. #       simple script to make amarok to work with some of my media buttons on the mouse.
  6. #       this script i wrote to work with xbindkeys
  7. #
  8. #       Needed stuff:
  9. #       xbindkeys
  10. #       evdev module compiled for Xorg "already bult in kubuntu's xorg server"
  11. #       kernel usbstuff- "evdev" module
  12. #
  13. #       cat /proc/bus/input/devices
  14. #       looks something like:
  15. #
  16. #       I: Bus=0003 Vendor=046d Product=c50e Version=0111
  17. #       N: Name="Logitech USB RECEIVER"
  18. #       P: Phys=usb-0000:00:0b.0-4/input0
  19. #       S: Sysfs=/class/input/input4
  20. #       U: Uniq=
  21. #       H: Handlers=mouse0 event1 ts0
  22. #       B: EV=20007
  23. #       B: KEY=ffff0000 0 0 0 0 0 0 0 0
  24. #       B: REL=143
  25. #       B: LED=ff00
  26. #
  27. #       Find your mouse event. usaly event0 or event1
  28. #       Now edit /etc/X11/xorg.conf and replace
  29. #
  30. #       Driver "mouse"
  31. #               with
  32. #       Driver "evdev"
  33. #               and
  34. #       Option "Device" "/dev/psaux" #mice or whatever whats written there..
  35. #               with
  36. #       Option "Device" "/dev/input/event1"
  37. #
  38. #       Now use "xev" to find the button numbers.
  39. #       then make a new file called ".xbindkeysrc" in your home dir,
  40. #
  41. #       the file may look something like.
  42. #
  43. #       ############# .XBINDKEYSRC #############
  44. #
  45. #       "/usr/bin/mediamouse start"
  46. #       b:17 + Release
  47. #
  48. #       "/usr/bin/mediamouse stop"
  49. #       b:10 + Release
  50. #
  51. #       "/usr/bin/mediamouse next"
  52. #       b:15 + Release
  53. #
  54. #       "/usr/bin/mediamouse prev"
  55. #       b:16 + Release
  56. #
  57. #       "/usr/bin/mediamouse up"
  58. #       b:13 + Release
  59. #
  60. #       "/usr/bin/mediamouse down"
  61. #       b:14 + Release
  62. #
  63. #       #########################################
  64. #
  65. #       copy the script to /usr/bin or change the path in .xbindkeysrc to where the script it located.
  66. #       also run "sudo chmod 755 mediamouse"
  67. #       this script is GPL and made by Stian Mikalsen, alias nuxil. [email protected]
  68. #
  69.  
  70. ARG=$1
  71. function start()
  72. {
  73.  
  74.         ## play/pause button toggle function.
  75.         ## if no amarok found running. start it up and play song from playlist.
  76.         if [[ ! `pgrep amarokapp` ]]
  77.  
  78.         ## start it up and sleep 3 secs. give it some time to load up
  79.         then exec amarokapp & sleep 3
  80.              exec dcop amarok player play
  81.  
  82.         ## if amarok is running.then we need a toogle function to toggle play pause..
  83.         else
  84.                 ## if a song is playing then pause.
  85.                 if [[ `dcop amarok player status` -eq "2" ]]
  86.                         then exec dcop amarok player pause
  87.                         else exec dcop amarok player play
  88.                 fi
  89.         fi
  90. }
  91.  
  92. function stop()
  93. {
  94.         if [[ `pgrep amarokapp` ]]
  95.         then exec dcop amarok player stop
  96.         fi
  97. }
  98.  
  99. function next()
  100. {
  101.         if [[ `pgrep amarokapp` ]]
  102.         then exec dcop amarok player next
  103.         fi
  104. }
  105.  
  106. function prev()
  107. {
  108.         if [[ `pgrep amarokapp` ]]
  109.         then exec dcop amarok player prev
  110.         fi
  111. }
  112.  
  113. function up()
  114. {
  115.         if [[ `pgrep amarokapp` ]]
  116.         then exec dcop amarok player volumeUp
  117.         fi
  118. }
  119.  
  120. function down()
  121. {
  122.         if [[ `pgrep amarokapp` ]]
  123.         then exec dcop amarok player volumeDown
  124.         fi
  125. }
  126.  
  127. ## forward 5 sec's
  128. function pfwd()
  129. {
  130.         if [[ `pgrep amarokapp` ]]
  131.         then CT=`dcop amarok player currentTime`
  132.  
  133.              # current minutte(s) time
  134.              CTM=`echo ${CT}  | tr ":" " " | awk '{print $1}'`
  135.              # current second(s) time
  136.              CTS=`echo ${CT}  | tr ":" " " | awk '{print $2}'`
  137.  
  138.              # 01, 02 so one. sometimes errors "bash outputs errors." . so we remove the 1st position of the string
  139.              # when its under 10,  and the lenght of the string to 1 position only
  140.              if [[ ${CTS:0:1} == "0" ]]
  141.              then CTS=${CTS:1:1}
  142.              fi
  143.              # make minutes and seconds to seconds only and forward 5 secs
  144.               MTS=$((${CTM:0} * 60))
  145.               ST=$((${MTS} + ${CTS} + 5))
  146.               exec dcop amarok player seek $ST
  147.         fi
  148. }
  149.  
  150. ## backwards 5 sec-. and under 10 sec playtime. 2 sec back
  151. function pbwd()
  152. {
  153.         if [[ `pgrep amarokapp` ]]
  154.         then CT=`dcop amarok player currentTime`
  155.  
  156.              # current minutte(s) time
  157.              CTM=`echo ${CT}  | tr ":" " " | awk '{print $1}'`
  158.              # current second(s) time
  159.              CTS=`echo ${CT}  | tr ":" " " | awk '{print $2}'`
  160.              # make minutes and seconds to seconds only
  161.              MTS=$((${CTM:0} * 60))
  162.              ST=$((${MTS} + ${CTS}))
  163.              # 01, 02 so one. sometimes errors "bash outputs errors." . so we remove the 1st position of the string
  164.              # when its under 10,  and the lenght of the string to 1 position only
  165.              if [[ ${CTS:0:1} == "0" ]]
  166.              then CTS=${CTS:1:1}
  167.                   BWD=$(($ST - 2))
  168.                   exec dcop amarok player seek $BWD
  169.             # over 10 means over 10 sec. then we increase time backwards to -5
  170.             else CTS=${CTS:0}
  171.                   BWD=$(($ST - 5))
  172.                   exec dcop amarok player seek $BWD
  173.              fi
  174.         fi
  175. }
  176.  
  177. case $ARG in start)
  178.         start
  179.         ;;
  180.         stop)
  181.         stop
  182.         ;;
  183.         next)
  184.         next
  185.         ;;
  186.         prev)
  187.         prev
  188.         ;;
  189.         up)
  190.         up
  191.         ;;
  192.         down)
  193.         down
  194.         ;;
  195.         pfwd)
  196.         pfwd
  197.         ;;
  198.         pbwd)
  199.         pbwd
  200.         ;;
  201.         *)
  202.         exit 0
  203.         ;;
  204. 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.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



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.

comments powered by Disqus
worth-right
worth-right