How to execute programms on unlock?

I would like to execute a program every time I unlock the screen of phosh. Ideally it should work on the phone the same way as on the desktop. I am currently on mobian but I will use this mechanism later on my L5, too.

I don’t have experience with dbus, but I tried find out if there is some message indicating the unlock that could be used for triggering a program start. I logged the buses to a file, locked the screen and unlocked it. In the session bus there were no results for either log nor lock. On the system bus there where no results for lock but here is what I found for log:

mobian@mobian:~/development/projects/execOnUnlock$ grep log dbus_system_lock.txt
signal time=1624024579.212102 sender=:1.2 -> destination=(null destination) serial=373 path=/org/freedesktop/login1/session/_32; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
string “org.freedesktop.login1.Session”
signal time=1624024579.214602 sender=:1.2 -> destination=(null destination) serial=374 path=/org/freedesktop/login1/seat/seat0; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
string “org.freedesktop.login1.Seat”
signal time=1624024579.216155 sender=:1.2 -> destination=(null destination) serial=375 path=/org/freedesktop/login1/user/_1000; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
string “org.freedesktop.login1.User”
signal time=1624024579.219100 sender=:1.2 -> destination=(null destination) serial=376 path=/org/freedesktop/login1; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
string “org.freedesktop.login1.Manager”
signal time=1624024580.776667 sender=:1.2 -> destination=(null destination) serial=378 path=/org/freedesktop/login1/session/_32; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
string “org.freedesktop.login1.Session”
signal time=1624024580.781937 sender=:1.2 -> destination=(null destination) serial=379 path=/org/freedesktop/login1/seat/seat0; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
string “org.freedesktop.login1.Seat”
signal time=1624024580.785519 sender=:1.2 -> destination=(null destination) serial=380 path=/org/freedesktop/login1/user/_1000; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
string “org.freedesktop.login1.User”
signal time=1624024580.793299 sender=:1.2 -> destination=(null destination) serial=381 path=/org/freedesktop/login1; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
string “org.freedesktop.login1.Manager”

To be honest I don’t know what to do with that. The sequence of events occurs twice. Maybe the first sequence is the lock and the second is the unlock. How can I get more details of these messages to distinguish them?

Or should I take another path? I am a newbie to systemd but I can imagine that is could be useful, too.

Depending on what program I want to start it actually might already be running. In that case it should be brought to the foreground instead of starting another instance. Some programs may behave like that out of the box. But this is only step two and i should be possible to start a small launcher program which takes care of this logic and eventually starts the app I want to pop up.

1 Like

How did you do that?

I just tried the dbus-monitor command on the Librem 5 and then I get the following when unlocking the screen (after entering the pin code):

signal time=1624034374.734646 sender=:1.27 -> destination=(null destination) serial=230 path=/org/gnome/ScreenSaver; interface=org.gnome.ScreenSaver; member=ActiveChanged
   boolean false
method call time=1624034374.737209 sender=:1.36 -> destination=:1.27 serial=77 path=/org/gnome/Mutter/IdleMonitor/Core; interface=org.gnome.Mutter.IdleMonitor; member=RemoveWatch
   uint32 7
method call time=1624034374.739222 sender=:1.27 -> destination=org.freedesktop.DBus serial=231 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=RemoveMatch
   string "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',path='/org/freedesktop/DBus',arg0=':1.36'"
method return time=1624034374.739316 sender=org.freedesktop.DBus -> destination=:1.27 serial=245 reply_serial=231

Did you also use dbus-monitor or you got your log in some other way?

1 Like

I used dbus-monitor with and without the --system option so I worked on session and system buses. There were plenty messages so I grep-ed for lock and log. I did not search for screen saver. So maybe that’s the thing I missed. I can’t look right now. My PinePhone has to charge. I will look later or tomorrow.

Thanks so far.

That IdleMonitor from Mutter looks a lot like the idle.xml Wayland protocol which is pretty easy to use. If you would use the Wayland protocol instead of the mutter specific DBus interface you would support almost all wayland compositors.