Switch monitors from the command line
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Life in a Drop
--
Chapters
00:00 Switch Monitors From The Command Line
00:23 Answer 1 Score 5
01:16 Accepted Answer Score 34
01:48 Answer 3 Score 0
02:33 Answer 4 Score 1
02:50 Thank you
--
Full question
https://superuser.com/questions/155004/s...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#ubuntu #multiplemonitors
#avk47
ACCEPTED ANSWER
Score 34
With the commands
xrandr --output VGA-0 --auto
xrandr --output LVDS --off
The screen automatically transfers to the external display. It doesn't even need sudo powers. To find out the name of the displays just do:
xrandr -q
Which should give something like:
VGA-0 connected 1280x1024+0+0 (normal left inverted right x axis y axis) 338mm x 270mm
...
LVDS connected (normal left inverted right x axis y axis)
...
Extending the displays can probably be achieved in a similar manner.
ANSWER 2
Score 5
This is most certainly NOT a direct answer to your question. But I found it helpful in my use case. This is not an export of the config file, but it does show how to automate disper in a shell script. I'm setting this up to run every time I dock/un-dock and it seems to be fixing my display issues when docking and undocking my laptop:
You have to have disper and Python installed.
#!/bin/sh
#
# Detect displays and move panels to the primary display
#
PYTHON=python2.6
DISPER=/usr/bin/disper
# disper command will detect and configure monitors
$PYTHON $DISPER --displays=auto -e -t left
# parse output from disper tool how many displays we have attached
# disper prints 2 lines per displer
lines=`$PYTHON $DISPER -l|wc -l`
display_count=$((lines / 2))
echo $display_count
echo "Detected display count:" $display_count
# Make sure that we move panels to the correct display based
# on the display count
if [ $display_count = 1 ] ; then
echo "Moving panels to the internal LCD display"
gconftool-2 \
--set "/apps/panel/toplevels/bottom_panel_screen0/monitor" \
--type integer "0"
gconftool-2 \
--set "/apps/panel/toplevels/top_panel_screen0/monitor" \
--type integer "0"
sleep 5
pkill gnome-panel
else
echo "Moving panels to the external display"
gconftool-2 \
--set "/apps/panel/toplevels/top_panel_screen0/monitor" \
--type integer "1"
gconftool-2 \
--set "/apps/panel/toplevels/bottom_panel_screen0/monitor" \
--type integer "1"
sleep 5
pkill gnome-panel
fi
ANSWER 3
Score 1
Based on @Malabarba response and xrandr man docs.
- Get monitors reference:
xrandr -q
- Set primary display:
xrandr --output <Monitor ref> --primary
Full example:
xrandr --output HDMI-1 --primary
ANSWER 4
Score 0
Just as an additional example stemming from the question/answer, here's the desktop launcher file I created which (1st) switches on the external monitor to the desired resolution and (2nd) then switches off the laptop screen.
[Desktop Entry]
Type=Application
Name[en_US]=Laptop > Ext
Exec=sh -c "xrandr --output HDMI-1 --mode 1366x768 && xrandr --output eDP-1 --off"
Encoding=UTF-8
Wrapping the commands in a shell means I can execute the two commands at once and point a keyboard shortcut to this .desktop file. So I've set one of my keyboard function keys to this desktop launcher (to switch from laptop to external) and then another key which runs the opposite desktop shortcut file. Saves a lot of time from the old way I was doing this (launching monitors control panel and manually enabling/disabling each one every time).