2

I'm attempting to make a new top bar for my system (Pop OS 22.04) using polybar. I have it all mostly working, and am attempting to make a power menu. I have the logout, power and restart buttons all working, but am struggling on the lock button.

I have a label with the left-click action set a bash script. I have confirmed that the script is getting executed as if I have script launch Firefox it does. The problem is that that I have not been able to find a working command. I have tried

gnome-screensaver-command --lock

xdg-screensaver lock

dbus-send --type=method_call --dest=org.gnome.ScreenSaver/org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock

They all work when run in the terminal, but not in a bash script. I think it may have somthing to do with polybar running them as root, so I tried running them as my user, but that did not solve it.

Is there some command that locks the screen of a specified user/desktop environment?

Thanks. Just comment if any more info is needed.

All of the commands mentioned where taken from answers from this question.

6
  • 1
    Could you try setting the display in the script? i.e. export DISPLAY=:0 && xdg-screensaver lock Commented Sep 26, 2024 at 16:24
  • 1
    Or some rough logic if the display is not using main default: export DISPLAY=${DISPLAY:-:0} && xdg-screensaver lock Commented Sep 26, 2024 at 16:27
  • Sure, I won't be able to check for a couple hours though. Commented Sep 26, 2024 at 16:28
  • 1
    I refused to believe this was only available through screensaver controls: loginctl lock-session. Commented Sep 26, 2024 at 17:00
  • 1
    I finally got some time to sit down and test this and have confirmed that it works. I would call it a "forceful" lock, as it skips the animation and blacks the screen. But it still works for what I need. I had no idea loginctl existed. Thank you! Commented Sep 27, 2024 at 13:43

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.