How do I create a script that runs when unlocking after sleep?

I have a script that uses ddcutil that turns my brightness up for my monitors. I have the script configured to start on startup, but that only works when logging in after booting the PC. If it goes into sleep, and then I relogin It doesnt work.

Things I’ve tried:

  • Creating a script in the systemd sleep folder
  • Creating a service that automatically runs the script
  • Disabling powerdevil in plasma

Right now I have it bind to a hotkey I can press, which yeah can work, but it would be nice to have a way to automate this properly. I would appreciate any help :pray:

Not exactly what you want, but you can use Settings > Notifications > Application specific settings > Configure > Screen saver > Configure events > Screen unlocked(*) to associate a script:

As far as a I can tell, the sleep mode is done inside a screen lock, so the wake up always goes through the unlocking.

Of course, this means that 1) you can only run “user” actions (or “sudoers” ones) and 2) running these action during a plain unlocking isn’t a problem (or you have a way to distinguish a plain unlock from a wake up unlock).

(*) in Settings 5.27.11on Kubuntu 24.04…

1 Like

I’m on the 6.3 Beta. I don’t see the option for run command. This is what I see in that menu

Then it may be time to ask the devs why so much functionality has been removed (or where it is now).

Where else can I ask? I figure this would be the appropriate place

Hi! This question actually came up here a couple of weeks ago, and while there isn’t a direct interface like the “Configure Notifications” dialog shown above from Plasma 5, some other approaches are definitely possible:

Hope that helps,

This worked. Thank you

1 Like
#!/bin/bash
firstlogin=true
gdbus monitor -y -d org.freedesktop.login1 | grep --line-buffered LockedHint |
  while read x; do
    case "$x" in 
      *"true"*)  echo "screen locked" & ;;
      *"false"*) echo "screen unlocked" & ;;  
    esac
  done