Create a gist now

Instantly share code, notes, and snippets.

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