Turn my screen blank through the command line

Ubuntu 24.04
Gnome, X11
How can I turn my screen blank through the command line? If possible using the same command as Ubuntu uses to turn screen blank, the reason is my previous OS (MX Linux) has a problem, when I used xset dpms command to turn off the screen, it won’t wake up (only solution for me is turn off the pc), not sure if Ubuntu has this problem or not, since the turn screen blank works, I’d like to use it if possible (through a command line/shortcut key).

Are you referring to Suspend in the Power menu?

If so, try this

systemctl suspend

@tea-for-one I’m not sure if it’s the same, when I went to Settings > Power > on the right side, under Power Saving I have 2 options 1) Screen Blank (set to 5min), below it Automatic Suspend (set to off), so my guess is not Suspend, I’m referring to Screen Blank (the one above).

Ah, I see where you are now.
Screen Blank and Suspend are different.

I am using Gnome Shell (which the Ubuntu Desktop is based upon) to blank the screen on command:

dbus-send --session --dest=org.gnome.ScreenSaver --type=method_call \
          /org/gnome/ScreenSaver org.gnome.ScreenSaver.SetActive boolean:true
2 Likes

@vanadium sorry, I’m not that knowledgeable about linux, can I use this command to create a shortcut key to blank screen, when I need to wake it up, just move the cursor or touch any key?

@vanadium has a very good suggestion, and there are many different ways on linux to do the same:
On a X11 session I just use this:

xset dpms force off

For Wayland, alternative methods are recommended to control the screen, such as using ydotool

1 Like

@vanadium thanks for this tip, I was used to use dpms to turn the screen off.

I actually have a more simple command that does the same, but that will work on any XDG compliant desktop:

xdg-screensaver activate
1 Like

@vanadium thanks so much for this tip, I’ll give it a try.