Last active
January 18, 2024 04:29
-
-
Save c-tamias35/bf61c908b20bfbc0937f61f17df707af to your computer and use it in GitHub Desktop.
systemd-inhibit alternative for XFCE 4
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 | |
#description :Wrapper to simulate systemd-inhibit (systemd 253) which doesn't work on XFCE 4.18 for now. | |
# This uses "xfce4-screensaver-command" for inhibiting screensaver/sleep/suspend/etc. | |
#usage :my-xcfe4-inhibit.sh YOUR_LONG_RUNNING_COMMAND | |
#note :This script should be chmod'ed to become executable. | |
# You can create an alias to call this script the way you want. | |
# e.g. if "alias inhibit='bash /home/user/bin/my-xcfe4-inhibit.sh '", you can then run "$ inhibit YOUR_COMMAND" like systemd-inhibit. | |
#author :c-tamias35@github | |
#date :2023-11-26 | |
#license :This code is licensed under MIT license | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND... | |
#============================== | |
inhibitorPID=-1 | |
# set your inhibitor binary (e.g. xfce4-screensaver-command) | |
INHIBITOR_BIN=$(whereis xfce4-screensaver-command | cut -d' ' -f2 | grep bin) | |
# check if inhibitor path is valid | |
if [ -z $INHIBITOR_BIN ] || [ ! -f $INHIBITOR_BIN ] || [ ! -x $INHIBITOR_BIN ]; then | |
echo "ERROR: INHIBITOR_BIN: $INHIBITOR_BIN not executable or found" | |
exit 1 | |
fi | |
# starting (i)nhibitor with (n)ame and (r)eason, in background | |
$INHIBITOR_BIN -i -n "$@[0]" -r 'my processing' & | |
inhibitorPID=$! | |
# kill background inhibitor on script exit | |
trap "kill $inhibitorPID" EXIT | |
# run your full (long-running) command with args | |
"$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment