3

Everytime I connect my pc to my tv using my HDMI cable (to watch my movies), I have to manually go to:

1- Monitors, to select "mirror" screen to HDMI 2- Sound, to select the HDMI as default sound output 3- Screen Off an Lock, to avoid screen locking while watching a video.

Is there a way I can automate this? Or at least write a script with commands that will do this. (I could manually run a script every time I connect my HDMI, and then run annother one to undo the changes later)

How can I do these actions from a Command Line?

1

3 Answers 3

2

xrandr can handle the display, but I'm not sure what would handle the audio portion.

Something like

#!/bin/bash
xrandr --output HDMI2 --primary --auto

should switch to HDMI2 as primary screen. You'll need to read some man-pages though and make sure the script works right for your configuration.

1
  • Ok, this helped me. Check my answer bellow. It is ALMOST done. Still need help with audio.
    – yurividal
    May 30, 2014 at 16:37
1

Try the program Disper:
This can be installed in a Terminal (CTRL+ALT+T).

sudo add-apt-repository ppa:disper-dev/ppa
sudo apt-get update
sudo apt-get install disper

Then do the following:

disper -l

Open Nvidia X Server Setting, you should see the external display is added. Configure TwinView should get you a dual monitor set up for your laptop. That's it.

Edit:
For the audio problem, do the following:
Open a Terminal (CTRL+ALT+T) and enter the following.

sudo apt-get install pavucontrol

Install the alsa mixer daily builds, what you can get here.

Open Pulse audio, go to the configuration tab in the drop down menu there is an option for HDMI audio out.

2
  • I dont think you understand. I already have HDMI audio out. It works. But everytime i connect the cable, i have to MANUALLY go to system settings, audio, and change the output to HDMI. I would like to do it thru command line, to be able to automate it.
    – yurividal
    May 30, 2014 at 16:55
  • Isn't that possible with that program?
    – Korkel
    May 30, 2014 at 16:57
1

Ok, your answers were very helpful. I'm able to disable lockscreen, and set screen mirror. But now, I'm still having trouble with changing audio output to HDMI. Here is how the script looks so far:

#!/bin/bash

HDMI_STATUS="$(cat /sys/class/drm/card0-HDMI-A-1/status)"

if [ "${HDMI_STATUS}" = connected ]; then
 dconf write /org/gnome/desktop/screensaver/lock-enabled false
 dconf write /org/gnome/desktop/screensaver/idle-activation-enabled false
 dconf write /org/gnome/desktop/screensaver/lock-delay 0
 xrandr --output HDMI1 --primary --mode 1360x768 --same-as LVDS1

else
 dconf write /org/gnome/desktop/screensaver/lock-enabled true
 dconf write /org/gnome/desktop/screensaver/idle-activation-enabled true
 dconf write /org/gnome/desktop/screensaver/lock-delay 120
fi

exit 0

How can I change the default audio output to HDMI?

1
  • I have editted my answer with some steps for the audio problem you have. I hope it helps you.
    – Korkel
    May 30, 2014 at 16:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .