You are not logged in.
Pages: 1
so, I sometimes use my tv as a second monitor when I write papers, so I can have a movie on in the background or something. I normally change the display settings with the default ARandR thing and the output settings with the default volume control thing. is there any way I can automate this?
I have two preconfigured layout settings for ARandR that I just load when I plug/unplug the hdmi cable, but have to change the audio output manually. I was thinking of maybe a script or maybe even some program that could automatically do this for me when the cable is plugged/unplugged. would this be possible?
thanks!
Last edited by penny dreadful (2013-12-09 20:05:36)
Offline
I use this script to toggle between hdmi sound/video output and output from laptop screen/speakers. I've bound it to fn+f6 to make it easy to swtich:
#!/bin/bash
# toggle_heads
# Get current (single) display
CURRENT="$(xrandr | grep -E 'connected [0-9]+' | head -1 | awk '{print $1}')"
# Perform switch
if echo $CURRENT | grep -q "HDMI1"; then
lvds
elif echo $CURRENT | grep -q "LVDS1"; then
hdmi
else # just in case
xrandr --auto
pactl set-card-profile 0 output:analog-stereo
fiIf the current output is hdmi it switches lo lvds and vice versa. The commands 'lvds' and 'hdmi' in the above are to separate scripts I've put in my ~/bin. Of course it could all go in the same file.
Here they are:
lvds:
#!/bin/sh
xrandr --output HDMI1 --off --output LVDS1 --mode 1366x768 --pos 0x0 --rotate normal --output DP1 --off --output VGA1 --off
nitrogen --restore
sleep 3s
conkywonky
sleep 1s
pactl set-card-profile 0 output:analog-stereo #switches sound
sleep 1s && suspend-onhdmi:
#!/bin/sh
xrandr --output HDMI1 --mode 1920x1080 --pos 0x0 --rotate normal --output LVDS1 --off --output DP1 --off --output VGA1 --off
nitrogen --restore
sleep 3s
conkywonky
sleep 1s
pactl set-card-profile 0 output:hdmi-stereo # switches sound
sleep 1s && suspend-offThe xrandr lines should off course be substituted with whatever you have in your two xrandr layout files. The pactl lines switcth audio output. That all you really need.
suspend-on off are two other script called from my ~/bin (I have a habit of making way to many separate scripts) that disable xautolock which is my only screen locker/auto suspend thingy. That way I can make sure that nothing interrupts me when I'm watching a movie on hdmi.
The lines that restart conky and nitrogen are necessary as things look weird if I change resolution midways. Might not be necessary on your setup ...
Last edited by tty-tourist (2013-12-08 15:03:04)
"You're just a tourist with a typewriter." - Charlie Meadows, Barton Fink
Offline
thanks! I edited the hdmi and lvds scrpts to match my configuration. I deleted the conky line, because I don't use conky, and I just kept the nitrogen lines in there just in case, and then threw them in ~/bin. now, is there anyplace special I put the main script? or do I just execute it manually from wherever it happens to be?
I'm assuming I keep that one in ~/bin as well, just so it knows what the 'lvds' and 'hdmi' commands mean, correct me if I am wrong.
Offline
Your welcome - glad it worked for you. Just put the main script in ~/bin as well. Then you can just press alt+f3 and type hdmi-toggle or whatever you choose to call it. If you use it a lot you could make a keyboard shortcut for it as well ...
"You're just a tourist with a typewriter." - Charlie Meadows, Barton Fink
Offline
worked perfectly, thank you!
Offline
Thanks for the help Andreas-r!
I'm still learning scripting (recently switched to #!) and was wondering why you wrote the main script in bash and the individual lvds and hdmi scripts in .sh (dash)?
Offline
Thanks for the help Andreas-r!
I'm still learning scripting (recently switched to #!) and was wondering why you wrote the main script in bash and the individual lvds and hdmi scripts in .sh (dash)?
On my system /bin/sh is a symlink to bash
Artwork at deviantArt; Iceweasel Personas; SLiM #! Themes; Openbox themes
Offline
On my system /bin/sh is a symlink to bash
What system are you using damo? On my unmodified #! system, /bin/sh is symlinked to dash, and I believe this is the Debian standard. On Arch /bin/sh is bash.
There are no stupid questions. Only stupid people.
Offline
Are there any bash-isms in those scripts that wouldn't work in Dash? It might be better to change them all to bash headers since debian defaults to dash now.
Offline
Are there any bash-isms in those scripts that wouldn't work in Dash? It might be better to change them all to bash headers since debian defaults to dash now.
I tested the bash script in dash, and it appears to work. I suspect that andreas-r copied the sh scripts from somewhere else and didn't change the headers. In any event, the scripts run so infrequently that it probably doesn't matter; change them all to bash if you like, or all to sh, and they will still work, AFAIK. The Debian init scripts all use sh(dash) -- it's supposed to be slightly faster; but in this case I doubt you will notice any difference.
Last edited by porkpiehat (2014-01-04 23:47:26)
There are no stupid questions. Only stupid people.
Offline
#! really is a good community, thanks for all the help!
Offline
I suspect that andreas-r copied the sh scripts from somewhere else and didn't change the headers.
Yup, very likely that I scrambled bits and pieces together. Anways it works for me but identical headers would be more elegant 
Last edited by tty-tourist (2014-01-06 10:30:42)
"You're just a tourist with a typewriter." - Charlie Meadows, Barton Fink
Offline
Pages: 1
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.