Skip to content

Instantly share code, notes, and snippets.

@auscompgeek
Last active July 25, 2017 01:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save auscompgeek/5da8f27e50feb185d1e2 to your computer and use it in GitHub Desktop.
Save auscompgeek/5da8f27e50feb185d1e2 to your computer and use it in GitHub Desktop.
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