SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2013-12-08 03:31:03

penny dreadful
Member
Registered: 2013-11-08
Posts: 13

[solved] HDMI script.

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

Be excellent to each other!

#2 2013-12-08 12:30:17

tty-tourist
#! CrunchBangian
From: within the swirl
Registered: 2013-05-26
Posts: 279

Re: [solved] HDMI script.

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
fi

If 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-on

hdmi:

#!/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-off

The 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

#3 2013-12-08 19:55:04

penny dreadful
Member
Registered: 2013-11-08
Posts: 13

Re: [solved] HDMI script.

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

#4 2013-12-08 20:20:06

tty-tourist
#! CrunchBangian
From: within the swirl
Registered: 2013-05-26
Posts: 279

Re: [solved] HDMI script.

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

#5 2013-12-09 20:05:52

penny dreadful
Member
Registered: 2013-11-08
Posts: 13

Re: [solved] HDMI script.

worked perfectly, thank you!

Offline

#6 2014-01-04 14:54:27

BrokenHammer
New Member
Registered: 2014-01-04
Posts: 3

Re: [solved] HDMI script.

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

#7 2014-01-04 15:35:19

damo
#! gimpbanger
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 4,440

Re: [solved] HDMI script.

BrokenHammer wrote:

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

#8 2014-01-04 15:45:41

porkpiehat
#! Die Hard
Registered: 2012-10-02
Posts: 880

Re: [solved] HDMI script.

damo wrote:

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

#9 2014-01-04 23:10:58

BrokenHammer
New Member
Registered: 2014-01-04
Posts: 3

Re: [solved] HDMI script.

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

#10 2014-01-04 23:46:16

porkpiehat
#! Die Hard
Registered: 2012-10-02
Posts: 880

Re: [solved] HDMI script.

BrokenHammer wrote:

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

#11 2014-01-05 13:41:42

BrokenHammer
New Member
Registered: 2014-01-04
Posts: 3

Re: [solved] HDMI script.

#! really is a good community, thanks for all the help!

Offline

#12 2014-01-06 10:30:02

tty-tourist
#! CrunchBangian
From: within the swirl
Registered: 2013-05-26
Posts: 279

Re: [solved] HDMI script.

porkpiehat wrote:

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 big_smile

Last edited by tty-tourist (2014-01-06 10:30:42)


"You're just a tourist with a typewriter." - Charlie Meadows, Barton Fink

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo