How do I run an app whenever I unlock?

Say, for example, I want to run the calculator app whenever I comeback to unlock the system after locking it or after suspend. I’m fairly certain it’s possible and I’ve tried to do a few things I found searching online, but I can’t seem to get it to work properly. Does anybody have a simple idea on how I can make this work?

What did you try?

I tried this thread I found in stackexchange. I can get the script to work when I run it from a terminal. What I can’t seem to do is have it run when I boot up.

If it is a while loop like the example there, then i would add it to ~/.xinitrc before the get_session function. It will run as soon as the DE/xserver has been started.

Edit: Don’t forget the “&” at the end of the while loop.

I was putting at the bottom of .xinitrc and nevere realized to put it before the get_session function. Thanks, I’ll try it and report back.

@megavolt I just tried it. Same results.

@wildcard Please post your script here :wink:

I used the one in the stackexchange thread

dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" |
  while read x; do
    case "$x" in
      *"boolean false"*) gnome-calculator;;  

When I create an executable it runs from a terminal and I can lock the system then unlock it, out comes the calculator. But when I try putting the script into .xinitrc and try a reboot it doesn’t work. Also tried putting the & in the end.

If that works, just put that script’s name in Gnome’s startup application and then it will be executed whenever you log in.

I would put a sleep 0.5 before the first done though as now it’s using a lot of CPU (Probably an entire core)


But OP wants it whenver its unlocked - including after suspend.

Best solution for me in the past was creating a systemd service.
(wants after, etc, etc … cant find my examples right now)
I think there are some versions on the old forum for restarting wifi after suspend and such.


Yeah, but his script is an endless loop that detects the system is unlocked, so yes, Systemd is the way to go, but as the current script is 98% there already, I’d put it in startup applications with a half second sleep…


@cscs When I was digging around for a solution I did come up with one suggesting creating a service. I did try it but I don’t remember what I did exactly. I’ll try to look for where I got the idea, but whatever it was it didn’t work. I may have done it wrong though. How would I go about doing it correctly?

@Fabby Should I just run the script as an executable? If so, I’m not sure how to add it to startup applications with a half second sleep.

post your service and we can take a look at it. Once you create the service test it by starting it manually.

systemctl start myservice

(where myservice is the name of your unit file (in this example the file would be myservice.service)

Once you test that it is working then enable the service so that it runs every time you startup your computer by typing the following:

systemctl enable myservice

I’m on KDE, not Gnome so you should try to find “startup application” or “startup” or “start” in your menu.

As said before:

Which means:

dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" |
  while read x; do
    case "$x" in
      *"boolean false"*) gnome-calculator;;  
    sleep 0.5


@cbDejaVu I can’t seem to find the example I used and I’ve already deleted the one I created. Sorry, I totally forgot what I did. But I do remember testing by starting it and it didn’t work.

@Fabby Thanks, I didn’t know about the sleep thing and you’re right would use a lot more of the CPU, so I’m kinda thinking of backing away from the idea since it’s not that big of a deal. It was more of quality of life thing.

Sorry for the late reply. I’ve been busy lately. I didn’t really go through with it, so should I still mark it as solved or just leave it?

Nah! Done! :wink:

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