Skip to content

Instantly share code, notes, and snippets.

@bhughes339
Created November 7, 2017 14:49
Show Gist options
  • Save bhughes339/32745a2ae1346f2e7747601e7f01425a to your computer and use it in GitHub Desktop.
Save bhughes339/32745a2ae1346f2e7747601e7f01425a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# Fix back and forward mouse buttons not working in Spotify on Linux
#
# Designed to be called from xbindkeys or a similar program:
# * Bind the back button to "spotify-mouse-buttons.sh back"
# * Bind the forward button to "spotify-mouse-buttons.sh forward"
#
# activate window under the mouse pointer
xdotool windowactivate $(xdotool getmouselocation | grep -o 'window:.*' | awk -F':' '{ print $2 }')
if [[ $1 == "back" ]]; then
xvkbd -text "\[XF86Back]"
elif [[ $1 == "forward" ]]; then
xvkbd -text "\[XF86Forward]"
fi
window="$(xprop -notype -id $(xdotool getactivewindow) 'WM_CLASS')"
if [[ $window == *"spotify"* ]]; then
if [[ $1 == "back" ]]; then
xte 'keydown Alt_L' 'key Left' 'keyup Alt_L'
elif [[ $1 == "forward" ]]; then
xte 'keydown Alt_L' 'key Right' 'keyup Alt_L'
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment