4

There's plenty of info out there on how to run a script at login (add it to .xprofile etc.), but I'm looking for a solution that will run a script/command not just at login but also every time a particular user's session is activated/brought to the foreground.

Concrete Example

I have two users on my system, John and Jane. On a typical day, John logs on to a graphical session in the morning, adjusts his settings the way he likes (for argument's sake, he works with the display backlight at 100%), does an hour of work, and then locks his session (but does not log out). A while later, Jane logs in, sets the backlight to 0%, does some work, locks her session, and leaves.

My issue is now, when John comes back, he unlocks and reactivates his earlier session. He curses Jane for setting the backlight to 0% again, and because he's not logging in to a new session, there's no option to automate backlight adjustment by adding commands to .xprofile or .xsessionrc

My Setup

I'm on debian buster with lightdm and xfce

Things I've Tried

The closest I've come to a solution is listening to dbus-monitor --system for lightdm or systemd-logind messages to hook into, but I just don't know how to identify a specific enough message trigger (specific to user and to session activation)

Question

How can one ensure a script gets run every time a particular user unlocks/reactivates his/her graphical session?

5
  • I realize the backlight is just an example, but would a solution that simply constantly monitors the backlight (or whatever) and then runs a script if certain conditions are not met work for you? I'm thinking you could have that run in the user's crontab and re-run the script whenever it detects that changes are necessary. Commented Aug 2, 2020 at 11:46
  • It's a bit peculiar that the display manager (lightdm) doesn't take care of that. The login screen should have these kind of settings set to their default values, unchangeable without root, no matter what the users did. At least that's my opinion in terms of UX, so it might worth ask lightdm what is their policy? Commented Aug 2, 2020 at 12:30
  • @terdon I'm not opposed to that approach, but I would still want the script to trigger immediately following reactivation of a users session. Identifying a reliable way to detect these conditions is the key to my whole problem, I think Commented Aug 2, 2020 at 13:00
  • If you authenticate users via pam, then you can use a custom pam module to run a script based on username after they typed a valid password to unlock. Commented Aug 3, 2020 at 7:09
  • @IporSircer It looks like pam is the piece I was missing. Do you want to post an answer and I can accept? Commented Aug 3, 2020 at 15:21

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.