Skip to content

Instantly share code, notes, and snippets.

@ssokolow
Created April 23, 2016 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssokolow/a5d242d6104a37cfd8d2067b322eb157 to your computer and use it in GitHub Desktop.
Save ssokolow/a5d242d6104a37cfd8d2067b322eb157 to your computer and use it in GitHub Desktop.
Quick hack to toggle play/pause in SMPlayer externally for global hotkey binding
#!/bin/bash
OLD_WID="$(xdotool getactivewindow)"
WID=""
until [ -n "$WID" ]; do
WID="$(xdotool search --name '[-][ ]SMPlayer' 2>/dev/null)"
done
echo "$WID"
# This seems to be race-y and this is the best mitigation I could find
# (--sync tends to hang xdotool when it would work, windowfocus is unreliable)
xdotool windowactivate "$WID"
sleep 0.1 # http://serverfault.com/a/469249
xdotool key --window "$WID" space # EDIT THIS LINE TO CHANGE ACTION
xdotool windowactivate "$OLD_WID"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment