This tutorial will teach Linux users how to make a script in order to easily turn off their netbook or laptop's monitor (LCD screens) with a keystroke, to save battery life.
Are you using Linux and you want to save the life of your laptop/netbook's battery? Look no further, we have the solution for you! The following guide will teach you step-by-step with screenshots, how to make a script and create a shortcut key in order to easily turn off your LCD screen with a keystroke, to save the life of your notebook's battery.
We've tested this tutorial on the newly released Ubuntu 11.10 Beta 2 (Oneiric Ocelot) operating system and it's working like a charm. Please follow the instructions below carefully.
Step 1 - Install the requirements
First of all, we need to install a Python library, so just click the link below and let your package manager install the required package. After installation, close the package manager and proceed to the next step.
Step 2 - Make the script
Now that you've installed the required library (see above), all you need to do is to right click on your desktop and select the "Create New Document -> Empty Document" option.
Rename the file to monitor_off.sh. Now, open it with a double click, copy the code below and paste it in.
from Xlib import X
from Xlib.display import Display
display = Display(':0')
root = display.screen().root
X.ButtonPressMask | X.ButtonReleaseMask | X.PointerMotionMask,
X.GrabModeAsync, X.GrabModeAsync, 0, 0, X.CurrentTime)
X.GrabModeAsync, X.GrabModeAsync, X.CurrentTime)
subprocess.call('xset dpms force off'.split())
p = subprocess.Popen('gnome-screensaver-command -i'.split())
Save the file!
Right click on the monitor_off.sh file and choose "Properties".
Go to the "Permissions" tab and check the "Allow executing file as program" option.
Editor's note: Place the monitor_off.sh file somewhere on your home folder, but remember the path for the next step.
Step 3 - Make the shortcut
Click the Ubuntu logo to open the Unity Dash and search "keyboard" (without quotes). Click the "Keyboard" icon and the Keyboard app will open.
Go to the "Shortcuts" tab, select "Custom Shortcuts" option from the list and click the + button to add a new shortcut. In the "Name:" field write something like "Monitor Off Script" and in the command field write the path to the script, including the name of the script (e.g. /home/softpedia/monitor_off.sh). Click the "Apply" button when you're done.
To assign a keyboard shortcut, click the "Disabled" entry on the newly created shortcut line and press the desired key on your keyboard, when it says "New shortcut".
We've assigned F10 as the shortcut key for our monitor off script.
That's it! Close the Keyboard app and press the selected shortcut key to test the script. Is your monitor off now? Turn it back on with the Esc key or with a mouse click.
If you encounter issues with the tutorial, do not hesitate to drop a comment below. Have fun using Linux!