Last active
July 14, 2016 10:25
-
-
Save ByteCommander/5ecf6a989e25159eb1283988e3d2b5d5 to your computer and use it in GitHub Desktop.
restart Firefox instead of shutting down when power button is pressed
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 | |
seconds=5 | |
targetuser="bytecommander" | |
killprocess="firefox" | |
startprocess="firefox" | |
mytempfile="/tmp/powerbtn-touched" | |
if [ -e /tmp/powerbtn-touched ] && | |
[ $(date +%s --date="$seconds seconds ago") -lt $(date +%s -r "$mytempfile") ] | |
then | |
# run the original powerbtn.sh script | |
/etc/acpi/powerbtn-default.sh | |
# shut down in case the script does not trigegr that itself | |
shutdown now | |
else | |
# set tempfile's modification timestamp to be able to check when it ran the last time | |
touch -m "$mytempfile" | |
# try to softly close all windows of "$killprocess" and give them 5 seconds time | |
sudo -u "$targetuser" wmctrl -ic "$(wmctrl -lp | grep "$(pgrep $killprocess)" | tail -1 | awk '{ print $1 }')" | |
sleep 5 | |
# force-kill all remaining processes | |
killall -u "$targetuser" "$killprocess" | |
# restart the process | |
sudo -u "$targetuser" "$startprocess" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment