Created
September 18, 2015 12:12
-
-
Save tokland/0046f0e7c225fdfdefad to your computer and use it in GitHub Desktop.
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 | |
# | |
# Toggle the state (STOPPED/RUNNING) of a process, clicking to its window. | |
set -e | |
debug() { echo "$@" 2>&1; } | |
die() { local MESSAGE=$1 | |
debug "Error: $MESSAGE" | |
exit 1 | |
} | |
PID=$(xprop _NET_WM_PID | cut -d' ' -f3) | |
test "$PID" || die "Could not get PID" | |
debug "PID: $PID" | |
STATE=$(cat /proc/$PID/status | grep "^State:" | awk '{print $2}') | |
test "$STATE" || die "Could not get process state" | |
debug "State: $STATE" | |
if test "$STATE" = "T"; then # T = stopped | |
sudo kill -SIGCONT $PID | |
else | |
sudo kill -SIGSTOP $PID | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment