Run script after login (after the lock screen) after wakeup

I need to run my custom script

#!/bin/sh
sudo protonvpn c -r

on login.

NOT after boot!
NOT after restart!
NOT just after wakeup!
AFTER login (when I entered my user password after a wakeup)

Why I do not want to run the script after wakeup (before login)?
Yes, I can place the script to the /lib/systemd/system-sleep/ directory. But I get the following error:
systemd-sleep[235332]: [!] There has been no profile initialized yet. Please run 'protonvpn init'.

The error means that I must run the command AFTER login.

QUESTION:
How to run the script (a single terminal command) AFTER I logged in after wakeup?
In other words, where is the directory or a file where I can place my script or add a terminal command?

Hi!
Make sure the script have exec permissions, then add it into autostart settings in settings/ start shutdown

In the “Settings” -> “Startup and Shutdown” there are options:

Run on:
- Startup
- Logout
- Before session startup

I just tested with the “Run on: Startup” option, but it does not run on wakeup after sleep when I logged in. Are you sure that the script must run on wakeup after sleep after login screen? If yes, then maybe I do something wrong.

Hi!
Did you try before startup session? I think it should work that way

As I understand from the KDE documentation (sorry, I am not allowed to paste links) before startup session is used when I log out before log in:

It allows you to add programs or scripts so they automatically run during startup or shutdown of your Plasma™ session

But I do not log out.

The full workflow is the following:

“Sleep” (No logout!) -> “Wakeup” -> “Login (lock screen)” (just typing my user password) -> Run my script.

It must be some other option to do this (trigger the script or command after entering the password on the lock screen).

Hi!
Thisan really do the trick
Copy your script to /etc/profile. d/

I found a solution (works on KDE).

  1. Create the file.

     #!/bin/bash
    
     dbus-monitor --session "type='signal',interface='org.kde.ScreenSaver'" | \
     ( while true
         do read X
         if echo $X | grep "boolean false" &> /dev/null; then
             # PASTE YOUR COMMAND HERE
         fi
         done )
    
  2. Run it in background (do not kill).

The script will execute the command on unlock after wakeup.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.