I found this trick from Softpedia. And I found its very cool, So just wanna Share...
Here it starts......
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.
Install python-xlib
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.
#!/usr/bin/python
import time
import subprocess
from Xlib import X
from Xlib.display import Display
display = Display(':0')
root = display.screen().root
root.grab_pointer(True,
X.ButtonPressMask | X.ButtonReleaseMask | X.PointerMotionMask,
X.GrabModeAsync, X.GrabModeAsync, 0, 0, X.CurrentTime)
root.grab_keyboard(True,
X.GrabModeAsync, X.GrabModeAsync, X.CurrentTime)
subprocess.call('xset dpms force off'.split())
p = subprocess.Popen('gnome-screensaver-command -i'.split())
time.sleep(1)
while True:
print display.next_event()
p.terminate()
break
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!
Here it starts......
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.
#!/usr/bin/python
import time
import subprocess
from Xlib import X
from Xlib.display import Display
display = Display(':0')
root = display.screen().root
root.grab_pointer(True,
X.ButtonPressMask | X.ButtonReleaseMask | X.PointerMotionMask,
X.GrabModeAsync, X.GrabModeAsync, 0, 0, X.CurrentTime)
root.grab_keyboard(True,
X.GrabModeAsync, X.GrabModeAsync, X.CurrentTime)
subprocess.call('xset dpms force off'.split())
p = subprocess.Popen('gnome-screensaver-command -i'.split())
time.sleep(1)
while True:
print display.next_event()
p.terminate()
break
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!
No comments:
Post a Comment