Skip to content

Instantly share code, notes, and snippets.

@auscompgeek
Last active Jul 25, 2017
Embed
What would you like to do?
Universal Pause Button for X11
#!/bin/sh
# Universal Pause Button for X11
# by auscompgeek
# licensed under MIT/X11
# requires xdotool
me=pause-button
die() {
echo "$me: $*" >&2
exit 1
}
getprocstat() {
# XXX This probably breaks for process names with spaces.
set -- $(cat /proc/$1/stat)
echo $3
}
if [ -z "$DISPLAY" ]; then
die 'This is not an X11 display!'
fi
window_pid="$(xdotool getactivewindow getwindowpid)"
# because X11 is shit
if [ -z "$window_pid" ]; then
die 'Could not get active window OR the window does not expose its PID.'
fi
stat="$(getprocstat $window_pid)"
if [ -z "$stat" ]; then
die 'Process has empty status!?'
fi
sig=STOP
if [ "$stat" = "T" ]; then
sig=CONT
fi
kill -$sig $window_pid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment