Looking for way to turn a monitor off/on easily. A script of widget, or whatnot. At least one game I run under wine will use both screens if on. A little hard to play that way.
Announcement
Collapse
No announcement yet.
quick monitor off/on
Collapse
This topic is closed.
X
X
-
I wrote this little script a while back to toggle the second monitor on or off. I didn't like my videos being split between the monitors much like your game problem. This script worked perfectly in 12.04 but I haven't tested or modified it for 14.04 yet. You will need to modify it to suit your particular settings (screen resolution, 2nd monitor postition, etc). You need to look at the output of the xrandr program to determine what to change in the script below.
Code:#!/bin/sh # Toggle the second monitor On or Off depending on its current state. if xrandr | grep -q "DVI-0 connected 1440x900+1680+0" then xrandr --output DVI-0 --off else xrandr --output DVI-0 --auto --right-of VGA-0 fiDesktop PC: Intel Core-i5-4670 3.40Ghz, 16Gb Crucial ram, Asus H97-Plus MB, 128Gb Crucial SSD + 2Tb Seagate Barracuda 7200.14 HDD running Kubuntu 18.04 LTS and Kubuntu 14.04 LTS (on SSD).
Laptop: HP EliteBook 8460p Core-i5-2540M, 4Gb ram, Transcend 120Gb SSD, currently running Deepin 15.8 and Manjaro KDE 18.
- Top
- Bottom
Comment
-
Originally posted by kubicle View PostWhat's the output of "xrandr"?DVI-1-0 And DVI-1-1 ar from built in video. Horrid performance (aren't they all), so I put in a decent card. I'm running Nvidia 346 driver, so icon in system settings non-functional.Code:virgil@dads-kubuntu:~$ xrandr Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 16384 x 16384 DVI-I-0 disconnected (normal left inverted right x axis y axis) DVI-I-1 disconnected (normal left inverted right x axis y axis) DVI-I-2 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 597mm x 336mm 1920x1080 60.0*+ 59.9 50.0 60.1 60.0 50.0 1680x1050 60.0 1600x1200 60.0 1440x900 59.9 1400x1050 60.0 1280x1024 75.0 60.0 1280x960 60.0 1280x720 60.0 59.9 50.0 1152x864 75.0 1024x768 75.0 70.1 60.0 800x600 75.0 72.2 60.3 56.2 720x576 50.0 50.1 720x480 59.9 60.1 640x480 75.0 72.8 59.9 59.9 DVI-I-3 connected (normal left inverted right x axis y axis) 1920x1080 60.0 + 59.9 50.0 60.1 60.0 50.0 1680x1050 60.0 1600x900 60.0 1280x1024 75.0 60.0 1280x960 60.0 1280x800 59.8 1280x720 60.0 59.9 50.0 1024x768 75.0 60.0 1024x576 60.0 800x600 75.0 60.3 720x576 50.0 50.1 720x480 59.9 60.1 640x480 75.0 59.9 59.9 HDMI-0 disconnected (normal left inverted right x axis y axis)
Tried modifying script from Rod J to
but gotCode:#!/bin/sh # Toggle the second monitor On or Off depending on its current state. if xrandr | grep -q "DVI-1-3 connected 1920x1020+1920+0" then xrandr --output DVI-1-3 --off else xrandr --output DVI-1-3 --auto --right-of VGA-0 fi
monitor on and off when testing, same result when using DFP-1 instead of VGA-0 and wether second monitor is on or offCode:virgil@dads-kubuntu:~$ sh monitorswitch.sh xrandr: cannot find output "VGA-0"
What should I use in place of VGA-0 in the script? Nvidia settings calls left Monitor Viewsonic VC2753 Series(DFP-0), right is Benq GW2750H(DFP-1)
I think I try to automate too much, but something to work on, it keeps the kids off my computer because they can;t figure it out
- Top
- Bottom
Comment
-
Try:
1. This assumes DVI-I-3 is the monitor you wish to turn off/on, andCode:#!/bin/sh # Toggle the second monitor On or Off depending on its current state. if xrandr | grep -q "DVI-I-3 connected" then xrandr --output DVI-I-3 --off else xrandr --output DVI-I-3 --auto --right-of DVI-I-2 fi
2. That the monitor DVI-I-3 is on the right side of DVI-I-2
Also note that in DVI-I-X, the bold character is a capital "i" not the number "1"
- Top
- Bottom
Comment
-
It turns it off. Halfway there. Tried changin --auto to --on. No effect. Back to research for a bit.Originally posted by kubicle View PostTry:
1. This assumes DVI-I-3 is the monitor you wish to turn off/on, andCode:#!/bin/sh # Toggle the second monitor On or Off depending on its current state. if xrandr | grep -q "DVI-I-3 connected" then xrandr --output DVI-I-3 --off else xrandr --output DVI-I-3 --auto --right-of DVI-I-2 fi
2. That the monitor DVI-I-3 is on the right side of DVI-I-2
Also note that in DVI-I-X, the bold character is a capital "i" not the number "1"
- Top
- Bottom
Comment
-
The if statement might match both cases (monitor on and off), so the script always turns the monitor off (rather than toggling).Originally posted by vsreeser View PostIt turns it off. Halfway there. Tried changin --auto to --on. No effect. Back to research for a bit.
First try if the command "xrandr --output DVI-I-3 --auto --right-of DVI-I-2" actually works and turns the monitor back on. If it does, post "xrandr" output from both states monitor on/off, so we can create a better if statement.
- Top
- Bottom
Comment
-
xrandr --output DVI-I-3 --auto --right-of DVI-I-2 does turn the monitor back on.Originally posted by kubicle View PostThe if statement might match both cases (monitor on and off), so the script always turns the monitor off (rather than toggling).
First try if the command "xrandr --output DVI-I-3 --auto --right-of DVI-I-2" actually works and turns the monitor back on. If it does, post "xrandr" output from both states monitor on/off, so we can create a better if statement.
with monitor DVI-I-3 off
with DVI-I-3 onCode:virgil@dads-kubuntu:~$ xrandr Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 16384 x 16384 DVI-I-0 disconnected (normal left inverted right x axis y axis) DVI-I-1 disconnected (normal left inverted right x axis y axis) DVI-I-2 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 597mm x 336mm 1920x1080 60.0*+ 59.9 50.0 60.1 60.0 50.0 1680x1050 60.0 1600x1200 60.0 1440x900 59.9 1400x1050 60.0 1280x1024 75.0 60.0 1280x960 60.0 1280x720 60.0 59.9 50.0 1152x864 75.0 1024x768 75.0 70.1 60.0 800x600 75.0 72.2 60.3 56.2 720x576 50.0 50.1 720x480 59.9 60.1 640x480 75.0 72.8 59.9 59.9 DVI-I-3 connected (normal left inverted right x axis y axis) 1920x1080 60.0 + 59.9 50.0 60.1 60.0 50.0 1680x1050 60.0 1600x900 60.0 1280x1024 75.0 60.0 1280x960 60.0 1280x800 59.8 1280x720 60.0 59.9 50.0 1024x768 75.0 60.0 1024x576 60.0 800x600 75.0 60.3 720x576 50.0 50.1 720x480 59.9 60.1 640x480 75.0 59.9 59.9 HDMI-0 disconnected (normal left inverted right x axis y axis)
They seem to look the same. I've been looking for some way to find the status, but haven't found anything yetCode:virgil@dads-kubuntu:~$ xrandr Screen 0: minimum 8 x 8, current 3840 x 1080, maximum 16384 x 16384 DVI-I-0 disconnected (normal left inverted right x axis y axis) DVI-I-1 disconnected (normal left inverted right x axis y axis) DVI-I-2 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 597mm x 336mm 1920x1080 60.0*+ 59.9 50.0 60.1 60.0 50.0 1680x1050 60.0 1600x1200 60.0 1440x900 59.9 1400x1050 60.0 1280x1024 75.0 60.0 1280x960 60.0 1280x720 60.0 59.9 50.0 1152x864 75.0 1024x768 75.0 70.1 60.0 800x600 75.0 72.2 60.3 56.2 720x576 50.0 50.1 720x480 59.9 60.1 640x480 75.0 72.8 59.9 59.9 DVI-I-3 connected 1920x1080+1920+0 (normal left inverted right x axis y axis) 598mm x 336mm 1920x1080 60.0*+ 59.9 50.0 60.1 60.0 50.0 1680x1050 60.0 1600x900 60.0 1280x1024 75.0 60.0 1280x960 60.0 1280x800 59.8 1280x720 60.0 59.9 50.0 1024x768 75.0 60.0 1024x576 60.0 800x600 75.0 60.3 720x576 50.0 50.1 720x480 59.9 60.1 640x480 75.0 59.9 59.9 HDMI-0 disconnected (normal left inverted right x axis y axis)
- Top
- Bottom
Comment
-
This should suffice:
Code:#!/bin/sh # Toggle the second monitor On or Off depending on its current state. if xrandr | grep -q "DVI-I-3 connected 1920" then xrandr --output DVI-I-3 --off else xrandr --output DVI-I-3 --auto --right-of DVI-I-2 fi
- Top
- Bottom
Comment
-
realy ,,,,,,I am running Nvidia-346.35 as well ,,,,,,and I can turn off the second display in system settings>display and monitor just fine ,,,,,,,,,,,, strange.Originally posted by vsreeser View PostI'm running Nvidia 346 driver, so icon in system settings non-functional.
VINNYi7 4core HT 8MB L3 2.9GHz
16GB RAM
Nvidia GTX 860M 4GB RAM 1152 cuda cores
- Top
- Bottom
Comment
-
I just modified my original script to update it with my new system (same two monitors though, but xrandr gives different results). It's working fine here.
Toggle2ndMonitor.sh:
Code:#!/bin/sh # Toggle the second monitor On or Off depending on its current state. # v1.1 changed to suit new system running Kubuntu 14.04 if xrandr | grep -q "HDMI1 connected 1440x900+1680+0" then xrandr --output HDMI1 --off else xrandr --output HDMI1 --auto --right-of VGA1 fiDesktop PC: Intel Core-i5-4670 3.40Ghz, 16Gb Crucial ram, Asus H97-Plus MB, 128Gb Crucial SSD + 2Tb Seagate Barracuda 7200.14 HDD running Kubuntu 18.04 LTS and Kubuntu 14.04 LTS (on SSD).
Laptop: HP EliteBook 8460p Core-i5-2540M, 4Gb ram, Transcend 120Gb SSD, currently running Deepin 15.8 and Manjaro KDE 18.
- Top
- Bottom
Comment
-
Also addedOriginally posted by kubicle View PostThis should suffice:
Code:#!/bin/sh # Toggle the second monitor On or Off depending on its current state. if xrandr | grep -q "DVI-I-3 connected 1920" then xrandr --output DVI-I-3 --off else xrandr --output DVI-I-3 --auto --right-of DVI-I-2 fi
killall conky
conky
to get conky back in the right position.
That works. Now I'll just make it into a shortcut, find a light switch icon (have to figure out how to assign an icon to a script) and throw it onto the panel.
Looked everything over and I'm not sure how you figured that out. Would like to know as I might be able to apply to something in the future. If you would be so kind. Might help someone else tooLast edited by vsreeser; Feb 14, 2015, 10:55 PM.
- Top
- Bottom
Comment
-
You can create a .desktop file your script (and put it in your menu) with kmenuedit. You can set the icon (and optionally a keyboard shortcut for even faster toggling), you can then add the icon to the panel from the menu.Originally posted by vsreeser View PostThat works. Now I'll just make it into a shortcut, find a light switch icon (have to figure out how to assign an icon to a script) and throw it onto the panel.
If you look at your xrandr output when the monitor is on/off:Originally posted by vsreeser View PostLooked everything over and I'm not sure how you figured that out. Would like to know as I might be able to apply to something in the future. If you would be so kind. Might help someone else too
On: DVI-I-3 connected 1920x1080+1920+0 (normal left inverted right x axis y axis) 598mm x 336mm
Off: DVI-I-3 connected (normal left inverted right x axis y axis)
And we needed a grep match for only the "On" Status. "DVI-I-3 connected 1920" will match when the monitor is on, but not when it's off.
- Top
- Bottom
Comment
Users Viewing This Topic
Collapse
There are 0 users viewing this topic.





Comment