Created
April 27, 2012 09:03
-
-
Save monstermunchkin/2507621 to your computer and use it in GitHub Desktop.
Sending keycodes to unfocused window (e.g. Spotify)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
KEY_NEXT=XF86AudioNext # keycode: 171 | |
KEY_PLAY=XF86AudioPlay # keycode: 172 | |
KEY_PREV=XF86AudioPrev # keycode: 173 | |
# the window id of Spotify | |
SPOTIFY_WID=$(xdotool search --name "Spotify - Linux Preview") | |
if [[ -n ${SPOTIFY_WID} ]]; then | |
# if Spotify instance is running send keycode to Spotify ... | |
ACTIVE_WID=${SPOTIFY_WID} | |
else | |
# ... otherwise send to active (focused) window | |
ACTIVE_WID=$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/ {print $NF}') | |
fi | |
case "${1}" in | |
prev) | |
xdotool key --window ${ACTIVE_WID} ${KEY_PREV};; | |
next) | |
xdotool key --window ${ACTIVE_WID} ${KEY_NEXT};; | |
play) | |
xdotool key --window ${ACTIVE_WID} ${KEY_PLAY};; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment