Icon Celebrity Journal
general /

How to turn off your monitor with a hotkey in ubuntu

How can I make a script (or make some changes) to allow me to turn the screen off in Ubuntu (12.04) whenever I want, the way thevscreen can be turned off in Cellphones?

And how can I make a combination of keys (a shortcut) to execute that script?

I want to conserve power.

I’ve seen this question

Turning Monitor Off With an Icon but there is no hotkey for it.

Moreover, in the answer, it is said that there are many ways to accomplish this so I’d like to know more.

4 Answers 4

If I understood well your question, you could use this commmand

In your settings, go to keyboard, shortcut, click on plus, write the name you want and past the command I just wrote, click on the new short cut and use the combination or key you want to use

Custom shortcuts to do this with newer versions of Ubuntu (e.g. 16.04) seems to require a delay from pressing the key combination to running the command. The simplest solution is to modify the shortcut command using sh .

Go to System Settings. | Keyboard | Shortcuts | Custom Shortcuts . Create a new custom shortcut and in Command put:

You can change the delay but I found 0.1s was not quite enough sometimes.

How to turn off your monitor with a hotkey in ubuntu

The command is xset dpms force off

Just create a keyboard shortcut for it. Go to keyboard->shortcuts. go to custom shortcuts . & then click on the + icon to create a new shortcut.

Then assign the above & assign custom key combination.

How to turn off your monitor with a hotkey in ubuntu

At the beginning I also configured a key shortcut with

But after 2 seconds the display turned on again. Maybe my newer Ubuntu Version (15.05) is the reason for this different behaviour. The solution was to create a script with the following content:

Now call this script every time you press the shortcut.

I think this method works because of any delayed key press event. With the sleep command all key events have 1 second to be processed and they do not wake the screen up again.

The Traditional way of turning your monitor off via hotkey has been broken for a few newer versions. A Python script can bring that functionality back in a reliable and efficient manner.

The older way to turn off hotkey is by using this command:

To Turn off the monitor using a hotkey, you need to have some dependencies, which we have to resolve open up the terminal, and check whether the required package is installed or not?

In my case, it is not installed to install these python and Xlib packages open up the terminal and type the following command:

It will install the python and python-xlib packages, the next step is to open up text editor (gedit or any other editor of your own choice) and copy/paste the following text:

How to turn off your monitor with a hotkey in ubuntu

Save your file somewhere, I saved it with the name screen_off.sh, by default it saved under the user’s home directory.

The next step is to allow this file to executable. Go to the properties of that file and click on the check box “Allow Executing file as program” keep all other settings the same and click Close.

How to turn off your monitor with a hotkey in ubuntu

To add a custom shortcut for this file, go to the keyboard layout setting and add a shortcut key, I set Ctrl + 4 you can add of your own choice and click on add appears at the right top corner.

How to turn off your monitor with a hotkey in ubuntu

As you can see that shortcut key has been added or you can execute this file by using simple command ./screen.off.sh.

If you want to turn off the monitor using the Shortcut press Ctrl+4 key, it will execute the Script and turn off the monitor.

To directly execute the script using the following command as shown in the figure, it will turn off the monitor.

You can also turn off the monitor using the following command:

Conclusion

In this article, you learn how to turn off the Monitor using a bash script with some pre-requisite packages in the Ubuntu Operating System. I hope this article will help you, how to turn off the Monitor Screen?

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn

I changed my laptop from a Lenovo U310 to a Dell Inspiron 7537. The Lenovo had a special key for turning off and on the screen, but the Dell doesn't have it. I want to know if there is a command for turning off and on the screen by using the same keyboard shortcut (something like CTRL+A, or similar).

Best Answer

There are two circumstances that make your situation a bit different from the supposed duplicate(s):

  1. Some process seems to wake your screen up, if your screen wakes up after the xset dpms force off command, it must be. My screen doesn't for example.
  2. If you don't want your screen to wake up, just with any key press, the xset dpms force off command is not doing what you want.

A workaround is the script below. What it does:

  • It looks up your screen's name and the current brightness
  • if the brightness is not equal to zero, it blacks the screen, else it sets brightness to normal

In other words: It toggles between black screen and normal brightness.

How to use

Copy the script into an empty file, save it as toggle_screen.py

Run it by the command:

Make sure you can repeat the command with a black screen, or else you will have to log out to toggle back.

If it works as you'd like it to, add it to a keyboard shortcut: Choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command.

Do you want to turn off your monitor screen using a dedicated hotkey or shortcut key. Great, Just by using a simple python script you can customize your shortcut key in order to turn off your monitor screen easily. But first you need to install python and python-xlib packages.

Just have a glance at this article to find out how to turn off your monitor using shortcut key in Ubuntu 14.04.

Steps to turn off your monitor using shortcut key:

Step 1: First open your terminal by using “Ctrl + ALT + T” and then type: “sudo apt-get install python python-xlib”. Press enter.

How to turn off your monitor with a hotkey in ubuntu

Step 2: You’ll be prompted to provide your Ubuntu password for authentication. Just type your password and press enter.

Step 3: After that you may ask “Do you want to continue?”, just press ‘y'(yes) to continue.

How to turn off your monitor with a hotkey in ubuntu

Step 4: Type “exit” command in order to close your terminal.

Step 5: Now, open your Unity dash and type “gpedit”. You’ll see your text editor icon, just click on that to open.

How to turn off your monitor with a hotkey in ubuntu

Step 6: Type the following python script (as shown in the image below) into your text editor and save in a particular location.

How to turn off your monitor with a hotkey in ubuntu

Step 7: Now, go that saved file, right click on it and then click on properties. You may see a new window pops open. Under properties, go to “Permissions” tab.

How to turn off your monitor with a hotkey in ubuntu

Step 8: Under ‘Permissions’ tab, go to “Execute” option and then click on “Allow executing file as program” check box.

How to turn off your monitor with a hotkey in ubuntu

Step 9: Now, go to your Unity dash and then click on the gear icon in order to open “system settings”.

How to turn off your monitor with a hotkey in ubuntu

Step 10: Under ‘System settings’, click your keyboard icon as shown in the image below.

How to turn off your monitor with a hotkey in ubuntu

Step 11: Under ‘Keyboard’ option go to “Shortcuts” tab.

How to turn off your monitor with a hotkey in ubuntu

Step 12: Under ‘shortcuts’ tab, go to “custom shortcuts” and then press “+” sign to add your new shortcut. You may see a small window which contains name and command field.

How to turn off your monitor with a hotkey in ubuntu

Step 13: Now add the name and command of your shortcut key and then press “Apply” button.

How to turn off your monitor with a hotkey in ubuntu

Step 14: Finally to assign a shortcut key you need to click the row and press your key combination.

I changed my laptop from a Lenovo U310 to a Dell Inspiron 7537. The Lenovo had a special key for turning off and on the screen, but the Dell doesn’t have it. I want to know if there is a command for turning off and on the screen by using the same keyboard shortcut (something like CTRL+A, or similar).

1 Answer 1

There are two circumstances that make your situation a bit different from the supposed duplicate(s):

  1. Some process seems to wake your screen up, if your screen wakes up after the xset dpms force off command, it must be. My screen doesn’t for example.
  2. If you don’t want your screen to wake up, just with any key press, the xset dpms force off command is not doing what you want.

A workaround is the script below. What it does:

  • It looks up your screen’s name and the current brightness
  • if the brightness is not equal to zero, it blacks the screen, else it sets brightness to normal

In other words: It toggles between black screen and normal brightness.

How to use

Copy the script into an empty file, save it as toggle_screen.py

Run it by the command:

Make sure you can repeat the command with a black screen, or else you will have to log out to toggle back.

If it works as you’d like it to, add it to a keyboard shortcut: Choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command.

When working with Ubuntu, you may have noticed that there is not just one, but several ways to complete a task, allowing users to choose one depending on their preference. Shutting down your system is also one such process that can be done in several ways; these include using the command line or Ubuntu’s graphical user interface.

  • Via the user interface
  • Via the application launcher search bar
  • Via the Ubuntu command line, the terminal.

We have run the commands and procedures mentioned in this article on an Ubuntu 20.04 LTS system.

Method 1: Power Off using the UI

One of the simple ways to shut down your Ubuntu system is to use the menu accessible through the downward arrow located at the top right corner of your Ubuntu screen. This is the menu you will see when you click this arrow:

How to turn off your monitor with a hotkey in ubuntu

Click on the Power Off button located in the bottom right corner of this drop-down menu. The following dialog will display when you do so:

How to turn off your monitor with a hotkey in ubuntu

  • Cancel the power off process
  • Restart your system
  • Power Off the system

If you do not press any of the buttons, the system will automatically shut down after 60 seconds. The dialog even shows a countdown, by the delay of 10 seconds, after which your system will be powered off.

Method 2: Power Off Using the Application Launcher Search

Another quick method to shut down your system is to use the very useful, application launcher search bar. This bar can be accessed by hitting the Super/Windows key on your keyboard.

Enter the keywords “power off” in this search bar and you will see the Power Off utility in the search result as follows:

How to turn off your monitor with a hotkey in ubuntu

Click on the Power Off search result and you will be presented the same Power Off dialog, through which you can power off your system, restart it, or even cancel the shutdown process altogether.

Method 3: Power Off Using the Terminal

For a Terminal-savvy person, the Ubuntu command line also provides a way to shut down your Ubuntu system.

Open the Ubuntu command line, the Terminal, either through the application launcher search or the Ctrl+Alt+T shortcut.

Then enter the following command in order to power off the system:

As you can see in the above output, the shutdown command when used as described above will not power off the system right away. It will give the user some time, usually 1 minute, to save the important things they are working on.

There is, however, a way to shut down the system without any delay and prompt. This command requires sudo privileges as such an abrupt shutdown may harm the system. Here is the command that you can use:

The shutdown command also lets you schedule powering off your system. You can do this by the following command:

Where t is the time, in minutes, after which your system will be automatically powered off.

If you want to cancel this scheduled shutdown, run the following command in your Terminal:

So, these were 3 ways to shut down your Ubuntu system. Unfortunately, there is no default keyboard shortcut for shutting down Ubuntu. We will explain a way to create a custom shortcut for this purpose in another article.

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn

This is another gift to future me from present me. I made the mistake of not properly writing this down before so I had to search for the answer. The problem is, sometimes, it seems as though Plasma is not shutting off my external screens consistently. I can’t say why but I have a suspicion that it is due to a specific communication application as I can almost guarantee that it is preventing my screens from turning off. I don’t have definitive proof of this so I am not going to put it in writing.

My intent is to have a shortcut for turning off all my screens instead of just locking them and hoping that the desktop environment will do its job of turning them off. I do want to point out that when I was using Windows, both 7 and 10, I had this problem too so it is absolutely not an issue with Desktop Linux.

It is fun being able to understand how to talk to a Linux machine through the terminal using the CLI (Command Line Interface). The more you know about how to work with it, the more you will ultimately enjoy your journey in Linux. Here is my solution.

The Commands

The commands I found out there in the vastness of the world wide web lead me to this that I have tested on multiple machines. Two were running Tumbleweed with Plasma and the other Leap 15.2 with Plasma.

xset -display :0 dpms force off

The other command is to force the screen on. This is useful as I have had issues where after undocking my machine, my screen would forget to turn on. I can’t say the reason why but this could also use a Global Shortcut

The Script

I created a little shell script for turning off my screen called screenoff.sh . I can’t say for sure how all distributions handle this but I have a bin directory in my home folder, so this is where I have chosen to place this script.

Using nano, I created a bash script for this.

Then filled it in with this information

sleep 1
xset -display :0 dpms force off

The purpose of the sleep 1 line is to give me a chance to get my hand away form the keyboard and mouse so I don’t inadvertently cause the desktop environment to wake the screen.

Next I made the file executable. There are many ways to do it but since we are playing in the terminal:

To test this out, using krunner or open a terminal and type screenoff.sh should turn off your screen. If not, something is wrong and maybe we can figure it out…

Custom Shortcut

It is not real practical to open up krunner or a terminal just to shut off the screen when I have the power to create a custom shortcut in Plasma. Here is how to do it. First open up System Settings and choose the shortcuts module. Your system settings may look a bit different but I am sure you can figure it out. I have faith in you.

How to turn off your monitor with a hotkey in ubuntu

Next you have to select the “Custom Shortcuts” submodule.

At the bottom of the list there is an Edit button with a down arrow. Select that > New > Global Shortcut > Command/URL

Name it whatever makes sense for you. I chose the name “Screen Off” to make it pretty clear. Set your shortcut. I chose Meta+Alt+O.

How to turn off your monitor with a hotkey in ubuntu

Next, Select the Action tab and enter the path of the script you just created. In my case, it is:

How to turn off your monitor with a hotkey in ubuntu

Select Apply and test it out!

Final Thoughts

Plasma is real easy to customize to your liking. I am very happy with this small modification to make my desktop experience a bit more suited to my personal taste. I don’t expect that this is a very common use case but since I know I am an edge case in much of what I do, this helps me to remember and hopefully there will be at least one person that can use or adapt this to their own case.

I am not a terminal expert so if there is any way that this can be improved, please contact me or comment below

While you can always lock your computer using a WIN + L, which will, in turn, turn off the display, but here is something even more useful. A keyboard shortcut to turn off the monitor display. It will not lock down the computer, but only turn off the screen.

Turn monitor display off with keyboard shortcut in Windows 10

There are two ways of doing it, but both of them use the software, and they are free.

  1. Push Off Monitor
  2. Nircmd monitor off

While the first one is straight forward, the second will need a bit of work. So choose accordingly.

1] Push Off Monitor

On my laptop, there is no unique key to turn the display off, so I ended up using this portable software— Push Off Monitor. You can download and install the program. Push off monitor from here.

How to turn off your monitor with a hotkey in ubuntu

Once installed, launch the program by searching it from the Start Menu or the System Tray icon, i.e., near the clock.

If you press SHIFT + F1, it just turns the monitor display off. While the display is turned off, everything else works. The best way to understand is to play music on your computer, and then press the hotkey. You will still be able to hear the music.

The software uses Auto Hot Key Scripts, which it executes when the user uses the shortcut. The first part of the code turns off the screen, while the second part is where it captures the input when you press SHIFT + F1.

Download Turn off monitor from here

2] Nircmd monitor off

NirCmd is a small command-line utility that allows you to do some useful tasks without displaying any user interface. One of the features is to turn off the monitor. So if you run nircmd.exe monitor off in the Command Prompt, it will turn off the monitor.

Once you download the file, extract it. Locate nircmd.exe in the nircmd folder, and double-click to launch it. You may need admin privilege for the copy to work. You can right-click on the program and launch it with admin privileges.

It will open a small pop-up window with the option to extract it to the Windows directory so you can run it from the command line if you wish.

How to turn off your monitor with a hotkey in ubuntu

Since we are looking for a shortcut, you need to manually create one shortcut which can be executed using a hotkey. We suggest using the Alias Manager program to do it or follow the steps below:

How to turn off your monitor with a hotkey in ubuntu

  • Right-click on an empty place on the desktop, and choose to create a shortcut.
  • Right-click on the desktop, and then select New > Shortcut.
  • Use the browse button to locate the nircmd.exe. Make sure to add the extra command, so it looks similar to the path below:
  • Save it on the desktop.
  • The next step is to add a hotkey to the shortcut. Right-click on the shortcut and click on properties.
  • Switch to Shortcut tab, and then use then press the keys you want to use as Shortcut.

When you click on the shortcut, the monitor will turn off the display within 2 seconds. You can remove cmdwait 2000 if you want to turn off the monitor instantly.

7 COMMENTS

Both your answers assume some techno knowledege. Please rewrite both as if talking to a person who knows absolutely nothing about computers. Do not skip any tiny steps that are obvious to you, and necessary, but not obvious to a newby.

For example you could change your wording this way: “After you start the program [portable software— “Push Off Monitor.” Get app here: ]. It [the icon for the app] sits on the computer’s tray icon [ look at the bottom of your monitor screen and see other icons. It will hopefully go there after download.].

If you press SHIFT + F1, it just turns the monitor display off. To resume back make mouse or press key movements and then it turns it on. [Hunh. ] [Click the mouse or touch any key] [This ability may need to be added by a techno geek, within “device manager” (see control panel). Go to your start icon (window icon) in the lower left of the bar of icons at the bottom of your monitor screen). Type in “device manager” and scroll down to “keyboard” and “mice and also device pointers.” Ask the geek what to do there.)

[Once you have done this and created a “hotkey”, F key, “short cut” you might want sometime to change the key. If so do the following….]

It is possible to change the hotkey [define “hotkey”] Right-click on the software icon, and click on Settings. It will open the text box with an option where you can change the button, i.e. F1 to anything else and modifier, i.e. Shift to anything else.
Download Turn off monitor from here

To me my additions in the [ ] boxes would clarify your instructions a lot. Correct me if mine are inacurate.

Hello Brenda, Thanks for your comment. I have made the changes, and have added more details to it. You are right, the instructions were not clear.

I downloaded and tried the program. It turns my monitor off for about 3 seconds and then comes back on by itself (no key or mouse movement).

There are two ways mentioned in the post, which one did you try?

My old ASUS laptop had a hotkey function at F9 or 10, simple and easy to use and really nice when you want to keep the machine running but not be burning up the screen. How does this differ? Can we get something like this idea on a non-asus laptop? I have windows 10 pro by the way. Thanks so much.

It is similar to what was happening on the Asus laptop. Are you looking for one keypress to achieve this function?

First you have to install the vbetool package.

Now what?

Now you have to do several things. First, vbetool can only be run as root. So you have to add it to the sudoers file as a password-free command.

With that in mind, you now know you need to run on a terminal

And you have to add the following to your newly created sudoer file:

Save the file. If everything is ok, you’re almost done.

What next?

Just add the following 2 commands as 2 separate keyboard shortcuts. You can test the commands right away without key binding them, but once you blank your screen you will feel lost and won’t know how to turn it back on. There’s a trick though, don’t worry. Keep on reading.

To add a new keyboard shortcut you have to take into account the Ubuntu flavor you’re running on your computer. As an example, you can look here on how to add them on Xubuntu. In case of doubt, please read the documentation associated with your distro of choice.

As for the commands, to turn off add as shortcut:

And to turn on:

You can also try the commands without worry if you know some tricks to get it on. These tricks are important so you are not left out without option to turn the screen back on. They are also important if you make some mistake while adding the shortcuts.

The tricks

  • → The simplest is to just close the lid of your laptop (if you’re using one) and to open it again. The screen is now on as usual.
  • → Another one is to add the following command as a shortcut and use it while the screen is off.

vbetool (последним исправлял пользователь ckimes 2017-09-06 22:08:18)