Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Spotify Launch Script by Ben Kraft
  4.  
  5. # Borrows some commands from Spotify Control by Tommy Matilla:
  6. # http://sites.google.com/site/tommymattila/home/spotifycontrol
  7. # which itself is based on Stuart Colville's
  8. # http://muffinresearch.co.uk/archives/2009/10/22/ubuntu-lock-screen-and-pause-spotify/
  9.  
  10. # Requires wmctrl and xvkbd
  11.  
  12. WP="$HOME/.wine"
  13. SPATH="$HOME/.wine/drive_c/Program Files/Spotify/spotify.exe"
  14. TITLE=$(wmctrl -xl | grep -o -e "spotify.exe.Wine.*$" | grep -o -e "Spotify.*$")
  15. ACTIVEWIN=$(wmctrl -va ":ACTIVE:" 2>&1 | grep -o -e "0x.*$")
  16.  
  17. sendkeys () {
  18. wmctrl -xa "spotify.exe.Wine" || return 1
  19. xvkbd -q -delay 100 -text "$1"
  20. wmctrl -ia $ACTIVEWIN
  21. }
  22.  
  23. if [ -z $TITLE ] ; then
  24. echo "Spotify is not running!
  25. exit 1
  26. else
  27. sendkeys ' '
  28. fi
  29. exit 0
  30.  
  31. #!/bin/bash
  32.  
  33. # Spotify Launch Script by Ben Kraft
  34.  
  35. # Borrows some commands from Spotify Control by Tommy Matilla:
  36. # http://sites.google.com/site/tommymattila/home/spotifycontrol
  37. # which itself is based on Stuart Colville's
  38. # http://muffinresearch.co.uk/archives/2009/10/22/ubuntu-lock-screen-and-pause-spotify/
  39.  
  40. # Requires wmctrl and xvkbd
  41. # Usage:
  42. USAGE="
  43. usage: spotify [OPTIONS]
  44.  
  45. OPTIONS:
  46. --play: Starts Spotify playing if it isn't already
  47. --pause: Pauses Spotify if it isn't already
  48. --playpause: Toggles Spotify between playing and pausing
  49. --prev: Plays the previous song
  50. --next: Plays the next song
  51. --display: Prints the currently playing song and artist to stdout
  52. --notify-send: Use only *after* --display; also pops up a notification with currently playing song and artist
  53. --uri URI: tells Spotify to display URI (e.g. a playlist or user).
  54.  
  55. With no options, this script will kill a currently running instance of spotify if there is one. With --uri, it starts Spotify iff it isn't running. With any other option, it will return 1 if Spotify is not running.
  56. "
  57.  
  58. WP="$HOME/.wine"
  59. SPATH="$HOME/.wine/drive_c/Program Files/Spotify/spotify.exe"
  60. TITLE=$(wmctrl -xl | grep -o -e "spotify.exe.Wine.*$" | grep -o -e "Spotify.*$")
  61. ACTIVEWIN=$(wmctrl -va ":ACTIVE:" 2>&1 | grep -o -e "0x.*$")
  62.  
  63. sendkeys () {
  64. wmctrl -xa "spotify.exe.Wine" || return 1
  65. xvkbd -q -delay 100 -text "$1"
  66. wmctrl -ia $ACTIVEWIN
  67. }
  68.  
  69. if [ $# -eq 0 ] ; then
  70. if pgrep spotify.exe &>/dev/null ; then
  71. killall spotify.exe
  72. fi
  73. exec env WINEPREFIX="$WP" wine "$SPATH"
  74. elif [ "$1" == "--uri" ] ; then
  75. shift
  76. exec env WINEPREFIX="$WP" wine "$SPATH" /uri "$@"
  77. elif [ -z "$TITLE" ] ; then
  78. echo "Spotify is not running" >&2
  79. if [ "$@" = "--display --notify-send" ] ; then
  80. notify-send "Spotify is not running"
  81. fi
  82. exit 1
  83. else
  84. case "$1" in
  85. --playpause) #toggles
  86. sendkeys ' '
  87. ;;
  88.  
  89. --next)
  90. sendkeys 'C[Right]'
  91. ;;
  92.  
  93. --prev)
  94. sendkeys 'C[Left]'
  95. ;;
  96.  
  97. --pause) #pauses if playing; does nothing if not
  98. if [ -n "${TITLE:9}" ] ; then
  99. sendkeys ' '
  100. fi
  101. ;;
  102.  
  103. --play) #plays if paused; does nothing if not
  104. if [ -z "${TITLE:9}" ] ; then
  105. sendkeys ' '
  106. fi
  107. ;;
  108.  
  109. --display)
  110. if [ -n "${TITLE:9}" ] ; then
  111. OUT1="Now Playing"
  112. OUT2="${TITLE:9}"
  113. else
  114. OUT1="Spotify paused."
  115. OUT2=""
  116. fi
  117. echo "$OUT"
  118. if [ "$#" -ge 2 ] && [ $2 == "--notify-send" ] ; then
  119. notify-send "$OUT1" "$OUT2"
  120. fi
  121. ;;
  122. *)
  123. echo "$USAGE"
  124. exit 2
  125. ;;
  126. esac
  127. fi
  128.  
  129. exit 0
  130.  
  131. $ xev
  132. [example keypress: right option key on an apple USB keyboard]
  133.  
  134. KeyPress event, serial 33, synthetic NO, window 0x1200001,
  135. root 0x2e, subw 0x0, time 122600873, (-49,299), root:(679,325),
  136. state 0x0, keycode 255 (keysym 0xffec, Super_R), same_screen YES,
  137. XLookupString gives 0 bytes:
  138. XmbLookupString gives 0 bytes:
  139. XFilterEvent returns: False
  140.  
  141. KeyRelease event, serial 34, synthetic NO, window 0x1200001,
  142. root 0x2e, subw 0x0, time 122600971, (-49,299), root:(679,325),
  143. state 0x0, keycode 255 (keysym 0xffec, Super_R), same_screen YES,
  144. XLookupString gives 0 bytes:
  145. XFilterEvent returns: False
  146.  
  147. "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause" XF86AudioPlay
  148. "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop" XF86AudioStop
  149. "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next" XF86AudioNext
  150. "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous" XF86AudioPrevious
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement