Created
June 3, 2021 16:28
-
-
Save gimbo/56da6896043f14341b00c83f2f2425b8 to your computer and use it in GitHub Desktop.
A bash script to kill/restart xbar, in response to xbar issue #714
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
#!/usr/bin/env bash | |
# See https://github.com/matryer/xbar/issues/714 | |
getxbarpid () { | |
ps -Ac -o pid=,comm= | grep xbar | column -t | cut -d ' ' -f 1 | |
} | |
xbarpid="$(getxbarpid)" | |
if [ -z "$xbarpid" ] ; then | |
echo -n "xbar not running? Will try to start it... " | |
else | |
echo -n "killing xbar pid $xbarpid... " | |
kill $xbarpid | |
if [ $? -ne 0 ]; then | |
echo "kill failed? Return code: $?" | |
exit 1 | |
fi | |
sleep 2 | |
# Check it's really gone. | |
xbarpid2="$(getxbarpid)" | |
if [ -z "$xbarpid2" ] ; then | |
echo -n "gone; restarting... " | |
else | |
if [ $xbarpid -eq $xbarpid2 ] ; then | |
# Sometimes we need to bring out the big guns | |
echo -n "kill it with fire... " | |
# I use HUP here; seems to work; could be KILL otherwise? | |
kill -HUP $xbarpid | |
sleep 5 | |
else | |
# Restarted by something else? Leave it. | |
echo "new pid $xbarpid — abort!" | |
exit 1 | |
fi | |
fi | |
fi | |
open -ja /Applications/xbar.app | |
echo "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment