You are not logged in.

#1 2022-06-17 09:22:09

burny02
Member
Registered: 2021-07-01
Posts: 129

[SOLVED] mate-screensaver lock with sudo

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

#2 2022-06-17 10:32:24

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,275

Re: [SOLVED] mate-screensaver lock with sudo

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 --lock

where you replace $user$ with the user of your standard mate session.

Last edited by V1del (2022-06-17 10:37:14)

Offline

#3 2022-06-17 11:34:09

burny02
Member
Registered: 2021-07-01
Posts: 129

Re: [SOLVED] mate-screensaver lock with sudo

Brilliant,

This worked a real treat, thanks for your help @V1del. Brilliant as usual

Offline

Board footer

Powered by FluxBB