Is there a such thing as a systemd service that is session-sensitive?

I have a laptop that runs several desktop sessions, which are all gnome-based (gnome,budgie,pantheon).
Budgie and Pantheon don’t share the screen-locking mechanism of gnome, so I implement xscreenlock (or i3lock) to be run when the session starts.
When it comes to linking the screen-locker to the suspend daemon (lid-close or power-button), all of the options that I am finding point to creating a service that is triggered by, that executes an xscreensaver or i3lock command.
The issue is that the service is also active if the user logs into a gnome session, unless the service can be set to only go into effect in a specific desktop environment.

Or am I approaching this incorrectly?

Description=i3lock on suspend

ExecStart=/usr/bin/i3lock -c 141414


[Unit] Description=XScreensaver

ExecStart=/usr/bin/xscreensaver -no-splash


systemd services are “system” services, not specific to a Desktop session.
That is why Desktop settings are located in hidden directories in your User’s /home directory or partition… That way, the Desktop starts up only when a User logs in and is identified so that settings specific only for that User are loaded.

I suppose someone could specify enough conditions in the Unit file to cause User-specific behavior, but that’s doing things the hard way.


Perhaps run a script (rather than just executing i3lock directly) to test active sessions and desktop environments. Then determine further administrator actions from there.

For example, ’systemd-loginctl list-sessions’, ‘systemd-loginctl session-status <session ID>’ might provide info, as well as ‘w’ and ‘ps -u <user>’.