On 02/01/24 at 19:15, Valerio Vanni wrote:
This way, I don't have to remember to close kaffeine before suspend.

If you have Kaffeine always running on your system you can try this script:

#!/bin/sh

################################################################################
# Run from systemd-suspend.service to place under /usr/lib/systemd/system-sleep/
################################################################################


PATH=/sbin:/usr/sbin:/bin:/usr/bin

case "$1" in
    pre)
            #code execution BEFORE sleeping/hibernating/suspending
            /usr/bin/killall kaffeine
            /usr/bin/sleep 2
            /usr/sbin/rmmod cx23885
    ;;
    post)
            #code execution AFTER resuming
            /usr/sbin/modprobe cx23885
            /usr/bin/sleep 3
/usr/bin/su YOURUSER -c 'XDG_RUNTIME_DIR=/run/user/1000 DISPLAY=:0 XDG_CURRENT_DESKTOP=KDE /usr/bin/kaffeine >/dev/null 2>&1 &'
            /usr/bin/sleep 1
    ;;
esac

exit 0


In place of YOURUSER you've to put your username, if you doubt the command "whoami" will tell you. Check if XDG_RUNTIME_DIR, XDG_CURRENT_DESKTOP and DISPLAY have the same value that I set, use the command "echo $variableName" to verify. In the end don't put your script in /usr/sbin or /usr/bin use /usr/local/bin or /usr/local/sbin instead.

Cheers

--
Franco Martelli

Reply via email to