You are not logged in.
Pages: 1
Hi
I'm running a bash script as sudo (it needs to be)
I would however like to lock the screen. Is this possible as root? I found the command mate-screensaver-command --lock, but running as root or su -c I get failed to connect to D-BUS daemon
Last edited by burny02 (2022-06-17 11:36:10)
Offline
There are multiple ways around this, you could run your script as the normal user and just cache the sudo PW (... see sudo -v) for the real operation or run the real operation in the background, or use sudo to switch to your current user in the actual script when invoking the locker command.
For the literal question what you should be doing at the minimum is get the DBUS_SESSION_BUS_ADDRESS of your mate-session/your user see e.g. https://gist.github.com/AladW/de1c5676d93d05a5a0e1 but since this often is fairly predictable you could probably do something like
sudo -u $user$ DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u $user$)/bus mate-screensaver-command --lockwhere you replace $user$ with the user of your standard mate session.
Last edited by V1del (2022-06-17 10:37:14)
Offline
Brilliant,
This worked a real treat, thanks for your help @V1del. Brilliant as usual
Offline
Pages: 1