How to run xrandr commands at startup in Ubuntu
How can I run the following xrandr
command on startup?
xrandr
cvt 1368 768
xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
xrandr --addmode VGA1 1368x768_60.00
xrandr --output VGA1 --mode 1368x768_60.00
command-line display xrandr startup-applications display-resolution
add a comment |
How can I run the following xrandr
command on startup?
xrandr
cvt 1368 768
xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
xrandr --addmode VGA1 1368x768_60.00
xrandr --output VGA1 --mode 1368x768_60.00
command-line display xrandr startup-applications display-resolution
1
Hi Udhaya Kumar did you notice you have an answer? Please let me know if you manage.
– Jacob Vlijm
Jun 18 '15 at 16:48
add a comment |
How can I run the following xrandr
command on startup?
xrandr
cvt 1368 768
xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
xrandr --addmode VGA1 1368x768_60.00
xrandr --output VGA1 --mode 1368x768_60.00
command-line display xrandr startup-applications display-resolution
How can I run the following xrandr
command on startup?
xrandr
cvt 1368 768
xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
xrandr --addmode VGA1 1368x768_60.00
xrandr --output VGA1 --mode 1368x768_60.00
command-line display xrandr startup-applications display-resolution
command-line display xrandr startup-applications display-resolution
edited Jun 18 '15 at 7:09
Jacob Vlijm
63.5k9124218
63.5k9124218
asked Jun 18 '15 at 6:20
Udhaya Kumar
54113
54113
1
Hi Udhaya Kumar did you notice you have an answer? Please let me know if you manage.
– Jacob Vlijm
Jun 18 '15 at 16:48
add a comment |
1
Hi Udhaya Kumar did you notice you have an answer? Please let me know if you manage.
– Jacob Vlijm
Jun 18 '15 at 16:48
1
1
Hi Udhaya Kumar did you notice you have an answer? Please let me know if you manage.
– Jacob Vlijm
Jun 18 '15 at 16:48
Hi Udhaya Kumar did you notice you have an answer? Please let me know if you manage.
– Jacob Vlijm
Jun 18 '15 at 16:48
add a comment |
4 Answers
4
active
oldest
votes
Adding complicated commands to Startup Applications
In General, you can add commands to run on start up (log in) by choosing: Dash > Startup Applications > Add. In this case, you have a complicated command to run.
There are two options to do that:
write a separate script:
#!/bin/bash
cvt 1368 768
# xrandr only works in X11 sessions, not Wayland
[ "$XDG_SESSION_TYPE" = x11 ] || exit 0
xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
xrandr --addmode VGA1 1368x768_60.00
xrandr --output VGA1 --mode 1368x768_60.00
Copy the script into an empty file, save it as
set_monitor.sh
and add the following command to startup applications as described above.
/bin/bash /path/to/set_monitor.sh
Chain the commands to one (very long) command:
/bin/bash -c "cvt 1368 768&&xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync&&xrandr --addmode VGA1 1368x768_60.00&&xrandr --output VGA1 --mode 1368x768_60.00"
In this case, using
&&
between the commands will make each command run as soon (and if) the previous one is run succesfully, just like they are on separate lines.
Then add the command to Startup Applications, as described above.
Important note: adding xrandr commands to Startup Applications
Adding xrandr
commands to startup can be tricky; sometimes they break if they are run too early, before the desktop is fully loaded. Therefore you might (probably) need to add a little break into the command to (either) run the script or the command, like (in the last case):
/bin/bash -c "sleep 15&&cvt 1368 768&&xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync&&xrandr --addmode VGA1 1368x768_60.00&&xrandr --output VGA1 --mode 1368x768_60.00"
You might need to play a little with the sleep 15
to find the optimal time.
Note
I left out the first line:
xrandr
since it does nothin but display some information on your screen setup :)
3
You don't need to include thecvt
command if you already know your modeline.
– thethakuri
Dec 16 '16 at 7:49
1
The/bin/bash -c "..."
wrapping did the trick for me :)
– Superole
Oct 3 '17 at 13:22
On Kubuntu 17.10, I added the command without thesleep
part in 'Startup applications' by selecting the "Before Session startup" option.
– pat-s
Jan 1 '18 at 21:38
+1 for writing 3 years ago# xrandr only works in X11 sessions, not Wayland
. Good future proofing back then.
– WinEunuuchs2Unix
Sep 21 '18 at 2:53
add a comment |
According to this at the Now automate it on login section, I have made my own script 45custom_xrandr-settings
and placed it into /etc/X11/Xsession.d/
. It works fine for me under Ubuntu 14.04 LTS. You could place the code below after the case
command described in that section.
PRI_OUTPUT="DVI-0";
# Make and force resolution
myNewMode=$(cvt 1366 768 60 | grep -oP 'ModelineK.*') && #grep evrything after 'Modline'
myNewModeName="$(echo $myNewMode | grep -oP '"K[^"47]+(?=["47])' )" && #grep everything inside quotes
xrandr --newmode $myNewMode;
sleep 15;
xrandr --addmode $PRI_OUTPUT $myNewModeName;
I believe that the above is what you are looking for. You can see the available outputs simply by running the xrandr
command. The outputs may be VGA
, VGA-0
, DVI-0
, TMDS-1
or DisplayPort-0
.
Here is the complete script that I made.
# To configure xrandr automatically during the first login,
# save this script to your computer as /etc/X11/Xsession.d/45custom_xrandr-settings:
# If an external monitor is connected, place it with xrandr
# External output may be "VGA" or "VGA-0" or "DVI-0" or "TMDS-1"
# More info at http://www.thinkwiki.org/wiki/Xorg_RandR_1.2
PRI_OUTPUT="DVI-0";
SEC_OUTPUT="DisplayPort-0";
SEC_LOCATION="left"; # SEC_LOCATION may be one of: left, right, above, or below
case "$SEC_LOCATION" in
left|LEFT)
SEC_LOCATION="--left-of $PRI_OUTPUT"
;;
right|RIGHT)
SEC_LOCATION="--right-of $PRI_OUTPUT"
;;
top|TOP|above|ABOVE)
SEC_LOCATION="--above $PRI_OUTPUT"
;;
bottom|BOTTOM|below|BELOW)
SEC_LOCATION="--below $PRI_OUTPUT"
;;
*)
SEC_LOCATION="--left-of $PRI_OUTPUT"
;;
esac
# Make and force resolution
myNewMode=$(cvt 1366 768 60 | grep -oP 'ModelineK.*') && #grep evrything after 'Modline'
myNewModeName="$(echo $myNewMode | grep -oP '"K[^"47]+(?=["47])' )" && #grep everything inside quotes
xrandr --newmode $myNewMode;
sleep 15;
xrandr --addmode $PRI_OUTPUT $myNewModeName;
# Activate secondary out (display port)
xrandr | grep $SEC_OUTPUT | grep " connected "
if [ $? -eq 0 ]; then
# xrandr --output $SEC_OUTPUT --auto $SEC_LOCATION
xrandr --output $PRI_OUTPUT --mode $myNewModeName --output $SEC_OUTPUT --auto $SEC_LOCATION
else
xrandr --output $PRI_OUTPUT --mode $myNewModeName --output $SEC_OUTPUT --off
fi
add a comment |
Create the file ~/.xprofile
and put your lines in it. It is ran at the beginning of the X user session.
1
this didnt work. commands fire up too early.
– neckTwi
May 27 '17 at 6:33
@neckTwi Thanks, I found thatxrandr --output ...
doesn't work but the previous two lines works. All in all this works for me.
– golopot
May 28 '17 at 5:45
add a comment |
There's a way of doing that declaratively. I think it's much better.
Create a new file 90-monitor.conf
:
Path: /usr/share/X11/xorg.conf.d/90-monitor.conf
Content:
Section "Monitor"
Identifier "VGA1"
Modeline "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
EndSection
Section "Screen"
Identifier "Screen0"
Monitor "Monitor-VGA1"
DefaultDepth 24
SubSection "Display"
Depth 24
Modes "1368x768_60.00"
EndSubSection
EndSection
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f637911%2fhow-to-run-xrandr-commands-at-startup-in-ubuntu%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Adding complicated commands to Startup Applications
In General, you can add commands to run on start up (log in) by choosing: Dash > Startup Applications > Add. In this case, you have a complicated command to run.
There are two options to do that:
write a separate script:
#!/bin/bash
cvt 1368 768
# xrandr only works in X11 sessions, not Wayland
[ "$XDG_SESSION_TYPE" = x11 ] || exit 0
xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
xrandr --addmode VGA1 1368x768_60.00
xrandr --output VGA1 --mode 1368x768_60.00
Copy the script into an empty file, save it as
set_monitor.sh
and add the following command to startup applications as described above.
/bin/bash /path/to/set_monitor.sh
Chain the commands to one (very long) command:
/bin/bash -c "cvt 1368 768&&xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync&&xrandr --addmode VGA1 1368x768_60.00&&xrandr --output VGA1 --mode 1368x768_60.00"
In this case, using
&&
between the commands will make each command run as soon (and if) the previous one is run succesfully, just like they are on separate lines.
Then add the command to Startup Applications, as described above.
Important note: adding xrandr commands to Startup Applications
Adding xrandr
commands to startup can be tricky; sometimes they break if they are run too early, before the desktop is fully loaded. Therefore you might (probably) need to add a little break into the command to (either) run the script or the command, like (in the last case):
/bin/bash -c "sleep 15&&cvt 1368 768&&xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync&&xrandr --addmode VGA1 1368x768_60.00&&xrandr --output VGA1 --mode 1368x768_60.00"
You might need to play a little with the sleep 15
to find the optimal time.
Note
I left out the first line:
xrandr
since it does nothin but display some information on your screen setup :)
3
You don't need to include thecvt
command if you already know your modeline.
– thethakuri
Dec 16 '16 at 7:49
1
The/bin/bash -c "..."
wrapping did the trick for me :)
– Superole
Oct 3 '17 at 13:22
On Kubuntu 17.10, I added the command without thesleep
part in 'Startup applications' by selecting the "Before Session startup" option.
– pat-s
Jan 1 '18 at 21:38
+1 for writing 3 years ago# xrandr only works in X11 sessions, not Wayland
. Good future proofing back then.
– WinEunuuchs2Unix
Sep 21 '18 at 2:53
add a comment |
Adding complicated commands to Startup Applications
In General, you can add commands to run on start up (log in) by choosing: Dash > Startup Applications > Add. In this case, you have a complicated command to run.
There are two options to do that:
write a separate script:
#!/bin/bash
cvt 1368 768
# xrandr only works in X11 sessions, not Wayland
[ "$XDG_SESSION_TYPE" = x11 ] || exit 0
xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
xrandr --addmode VGA1 1368x768_60.00
xrandr --output VGA1 --mode 1368x768_60.00
Copy the script into an empty file, save it as
set_monitor.sh
and add the following command to startup applications as described above.
/bin/bash /path/to/set_monitor.sh
Chain the commands to one (very long) command:
/bin/bash -c "cvt 1368 768&&xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync&&xrandr --addmode VGA1 1368x768_60.00&&xrandr --output VGA1 --mode 1368x768_60.00"
In this case, using
&&
between the commands will make each command run as soon (and if) the previous one is run succesfully, just like they are on separate lines.
Then add the command to Startup Applications, as described above.
Important note: adding xrandr commands to Startup Applications
Adding xrandr
commands to startup can be tricky; sometimes they break if they are run too early, before the desktop is fully loaded. Therefore you might (probably) need to add a little break into the command to (either) run the script or the command, like (in the last case):
/bin/bash -c "sleep 15&&cvt 1368 768&&xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync&&xrandr --addmode VGA1 1368x768_60.00&&xrandr --output VGA1 --mode 1368x768_60.00"
You might need to play a little with the sleep 15
to find the optimal time.
Note
I left out the first line:
xrandr
since it does nothin but display some information on your screen setup :)
3
You don't need to include thecvt
command if you already know your modeline.
– thethakuri
Dec 16 '16 at 7:49
1
The/bin/bash -c "..."
wrapping did the trick for me :)
– Superole
Oct 3 '17 at 13:22
On Kubuntu 17.10, I added the command without thesleep
part in 'Startup applications' by selecting the "Before Session startup" option.
– pat-s
Jan 1 '18 at 21:38
+1 for writing 3 years ago# xrandr only works in X11 sessions, not Wayland
. Good future proofing back then.
– WinEunuuchs2Unix
Sep 21 '18 at 2:53
add a comment |
Adding complicated commands to Startup Applications
In General, you can add commands to run on start up (log in) by choosing: Dash > Startup Applications > Add. In this case, you have a complicated command to run.
There are two options to do that:
write a separate script:
#!/bin/bash
cvt 1368 768
# xrandr only works in X11 sessions, not Wayland
[ "$XDG_SESSION_TYPE" = x11 ] || exit 0
xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
xrandr --addmode VGA1 1368x768_60.00
xrandr --output VGA1 --mode 1368x768_60.00
Copy the script into an empty file, save it as
set_monitor.sh
and add the following command to startup applications as described above.
/bin/bash /path/to/set_monitor.sh
Chain the commands to one (very long) command:
/bin/bash -c "cvt 1368 768&&xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync&&xrandr --addmode VGA1 1368x768_60.00&&xrandr --output VGA1 --mode 1368x768_60.00"
In this case, using
&&
between the commands will make each command run as soon (and if) the previous one is run succesfully, just like they are on separate lines.
Then add the command to Startup Applications, as described above.
Important note: adding xrandr commands to Startup Applications
Adding xrandr
commands to startup can be tricky; sometimes they break if they are run too early, before the desktop is fully loaded. Therefore you might (probably) need to add a little break into the command to (either) run the script or the command, like (in the last case):
/bin/bash -c "sleep 15&&cvt 1368 768&&xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync&&xrandr --addmode VGA1 1368x768_60.00&&xrandr --output VGA1 --mode 1368x768_60.00"
You might need to play a little with the sleep 15
to find the optimal time.
Note
I left out the first line:
xrandr
since it does nothin but display some information on your screen setup :)
Adding complicated commands to Startup Applications
In General, you can add commands to run on start up (log in) by choosing: Dash > Startup Applications > Add. In this case, you have a complicated command to run.
There are two options to do that:
write a separate script:
#!/bin/bash
cvt 1368 768
# xrandr only works in X11 sessions, not Wayland
[ "$XDG_SESSION_TYPE" = x11 ] || exit 0
xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
xrandr --addmode VGA1 1368x768_60.00
xrandr --output VGA1 --mode 1368x768_60.00
Copy the script into an empty file, save it as
set_monitor.sh
and add the following command to startup applications as described above.
/bin/bash /path/to/set_monitor.sh
Chain the commands to one (very long) command:
/bin/bash -c "cvt 1368 768&&xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync&&xrandr --addmode VGA1 1368x768_60.00&&xrandr --output VGA1 --mode 1368x768_60.00"
In this case, using
&&
between the commands will make each command run as soon (and if) the previous one is run succesfully, just like they are on separate lines.
Then add the command to Startup Applications, as described above.
Important note: adding xrandr commands to Startup Applications
Adding xrandr
commands to startup can be tricky; sometimes they break if they are run too early, before the desktop is fully loaded. Therefore you might (probably) need to add a little break into the command to (either) run the script or the command, like (in the last case):
/bin/bash -c "sleep 15&&cvt 1368 768&&xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync&&xrandr --addmode VGA1 1368x768_60.00&&xrandr --output VGA1 --mode 1368x768_60.00"
You might need to play a little with the sleep 15
to find the optimal time.
Note
I left out the first line:
xrandr
since it does nothin but display some information on your screen setup :)
edited Jan 17 '18 at 16:37
muru
1
1
answered Jun 18 '15 at 6:46
Jacob Vlijm
63.5k9124218
63.5k9124218
3
You don't need to include thecvt
command if you already know your modeline.
– thethakuri
Dec 16 '16 at 7:49
1
The/bin/bash -c "..."
wrapping did the trick for me :)
– Superole
Oct 3 '17 at 13:22
On Kubuntu 17.10, I added the command without thesleep
part in 'Startup applications' by selecting the "Before Session startup" option.
– pat-s
Jan 1 '18 at 21:38
+1 for writing 3 years ago# xrandr only works in X11 sessions, not Wayland
. Good future proofing back then.
– WinEunuuchs2Unix
Sep 21 '18 at 2:53
add a comment |
3
You don't need to include thecvt
command if you already know your modeline.
– thethakuri
Dec 16 '16 at 7:49
1
The/bin/bash -c "..."
wrapping did the trick for me :)
– Superole
Oct 3 '17 at 13:22
On Kubuntu 17.10, I added the command without thesleep
part in 'Startup applications' by selecting the "Before Session startup" option.
– pat-s
Jan 1 '18 at 21:38
+1 for writing 3 years ago# xrandr only works in X11 sessions, not Wayland
. Good future proofing back then.
– WinEunuuchs2Unix
Sep 21 '18 at 2:53
3
3
You don't need to include the
cvt
command if you already know your modeline.– thethakuri
Dec 16 '16 at 7:49
You don't need to include the
cvt
command if you already know your modeline.– thethakuri
Dec 16 '16 at 7:49
1
1
The
/bin/bash -c "..."
wrapping did the trick for me :)– Superole
Oct 3 '17 at 13:22
The
/bin/bash -c "..."
wrapping did the trick for me :)– Superole
Oct 3 '17 at 13:22
On Kubuntu 17.10, I added the command without the
sleep
part in 'Startup applications' by selecting the "Before Session startup" option.– pat-s
Jan 1 '18 at 21:38
On Kubuntu 17.10, I added the command without the
sleep
part in 'Startup applications' by selecting the "Before Session startup" option.– pat-s
Jan 1 '18 at 21:38
+1 for writing 3 years ago
# xrandr only works in X11 sessions, not Wayland
. Good future proofing back then.– WinEunuuchs2Unix
Sep 21 '18 at 2:53
+1 for writing 3 years ago
# xrandr only works in X11 sessions, not Wayland
. Good future proofing back then.– WinEunuuchs2Unix
Sep 21 '18 at 2:53
add a comment |
According to this at the Now automate it on login section, I have made my own script 45custom_xrandr-settings
and placed it into /etc/X11/Xsession.d/
. It works fine for me under Ubuntu 14.04 LTS. You could place the code below after the case
command described in that section.
PRI_OUTPUT="DVI-0";
# Make and force resolution
myNewMode=$(cvt 1366 768 60 | grep -oP 'ModelineK.*') && #grep evrything after 'Modline'
myNewModeName="$(echo $myNewMode | grep -oP '"K[^"47]+(?=["47])' )" && #grep everything inside quotes
xrandr --newmode $myNewMode;
sleep 15;
xrandr --addmode $PRI_OUTPUT $myNewModeName;
I believe that the above is what you are looking for. You can see the available outputs simply by running the xrandr
command. The outputs may be VGA
, VGA-0
, DVI-0
, TMDS-1
or DisplayPort-0
.
Here is the complete script that I made.
# To configure xrandr automatically during the first login,
# save this script to your computer as /etc/X11/Xsession.d/45custom_xrandr-settings:
# If an external monitor is connected, place it with xrandr
# External output may be "VGA" or "VGA-0" or "DVI-0" or "TMDS-1"
# More info at http://www.thinkwiki.org/wiki/Xorg_RandR_1.2
PRI_OUTPUT="DVI-0";
SEC_OUTPUT="DisplayPort-0";
SEC_LOCATION="left"; # SEC_LOCATION may be one of: left, right, above, or below
case "$SEC_LOCATION" in
left|LEFT)
SEC_LOCATION="--left-of $PRI_OUTPUT"
;;
right|RIGHT)
SEC_LOCATION="--right-of $PRI_OUTPUT"
;;
top|TOP|above|ABOVE)
SEC_LOCATION="--above $PRI_OUTPUT"
;;
bottom|BOTTOM|below|BELOW)
SEC_LOCATION="--below $PRI_OUTPUT"
;;
*)
SEC_LOCATION="--left-of $PRI_OUTPUT"
;;
esac
# Make and force resolution
myNewMode=$(cvt 1366 768 60 | grep -oP 'ModelineK.*') && #grep evrything after 'Modline'
myNewModeName="$(echo $myNewMode | grep -oP '"K[^"47]+(?=["47])' )" && #grep everything inside quotes
xrandr --newmode $myNewMode;
sleep 15;
xrandr --addmode $PRI_OUTPUT $myNewModeName;
# Activate secondary out (display port)
xrandr | grep $SEC_OUTPUT | grep " connected "
if [ $? -eq 0 ]; then
# xrandr --output $SEC_OUTPUT --auto $SEC_LOCATION
xrandr --output $PRI_OUTPUT --mode $myNewModeName --output $SEC_OUTPUT --auto $SEC_LOCATION
else
xrandr --output $PRI_OUTPUT --mode $myNewModeName --output $SEC_OUTPUT --off
fi
add a comment |
According to this at the Now automate it on login section, I have made my own script 45custom_xrandr-settings
and placed it into /etc/X11/Xsession.d/
. It works fine for me under Ubuntu 14.04 LTS. You could place the code below after the case
command described in that section.
PRI_OUTPUT="DVI-0";
# Make and force resolution
myNewMode=$(cvt 1366 768 60 | grep -oP 'ModelineK.*') && #grep evrything after 'Modline'
myNewModeName="$(echo $myNewMode | grep -oP '"K[^"47]+(?=["47])' )" && #grep everything inside quotes
xrandr --newmode $myNewMode;
sleep 15;
xrandr --addmode $PRI_OUTPUT $myNewModeName;
I believe that the above is what you are looking for. You can see the available outputs simply by running the xrandr
command. The outputs may be VGA
, VGA-0
, DVI-0
, TMDS-1
or DisplayPort-0
.
Here is the complete script that I made.
# To configure xrandr automatically during the first login,
# save this script to your computer as /etc/X11/Xsession.d/45custom_xrandr-settings:
# If an external monitor is connected, place it with xrandr
# External output may be "VGA" or "VGA-0" or "DVI-0" or "TMDS-1"
# More info at http://www.thinkwiki.org/wiki/Xorg_RandR_1.2
PRI_OUTPUT="DVI-0";
SEC_OUTPUT="DisplayPort-0";
SEC_LOCATION="left"; # SEC_LOCATION may be one of: left, right, above, or below
case "$SEC_LOCATION" in
left|LEFT)
SEC_LOCATION="--left-of $PRI_OUTPUT"
;;
right|RIGHT)
SEC_LOCATION="--right-of $PRI_OUTPUT"
;;
top|TOP|above|ABOVE)
SEC_LOCATION="--above $PRI_OUTPUT"
;;
bottom|BOTTOM|below|BELOW)
SEC_LOCATION="--below $PRI_OUTPUT"
;;
*)
SEC_LOCATION="--left-of $PRI_OUTPUT"
;;
esac
# Make and force resolution
myNewMode=$(cvt 1366 768 60 | grep -oP 'ModelineK.*') && #grep evrything after 'Modline'
myNewModeName="$(echo $myNewMode | grep -oP '"K[^"47]+(?=["47])' )" && #grep everything inside quotes
xrandr --newmode $myNewMode;
sleep 15;
xrandr --addmode $PRI_OUTPUT $myNewModeName;
# Activate secondary out (display port)
xrandr | grep $SEC_OUTPUT | grep " connected "
if [ $? -eq 0 ]; then
# xrandr --output $SEC_OUTPUT --auto $SEC_LOCATION
xrandr --output $PRI_OUTPUT --mode $myNewModeName --output $SEC_OUTPUT --auto $SEC_LOCATION
else
xrandr --output $PRI_OUTPUT --mode $myNewModeName --output $SEC_OUTPUT --off
fi
add a comment |
According to this at the Now automate it on login section, I have made my own script 45custom_xrandr-settings
and placed it into /etc/X11/Xsession.d/
. It works fine for me under Ubuntu 14.04 LTS. You could place the code below after the case
command described in that section.
PRI_OUTPUT="DVI-0";
# Make and force resolution
myNewMode=$(cvt 1366 768 60 | grep -oP 'ModelineK.*') && #grep evrything after 'Modline'
myNewModeName="$(echo $myNewMode | grep -oP '"K[^"47]+(?=["47])' )" && #grep everything inside quotes
xrandr --newmode $myNewMode;
sleep 15;
xrandr --addmode $PRI_OUTPUT $myNewModeName;
I believe that the above is what you are looking for. You can see the available outputs simply by running the xrandr
command. The outputs may be VGA
, VGA-0
, DVI-0
, TMDS-1
or DisplayPort-0
.
Here is the complete script that I made.
# To configure xrandr automatically during the first login,
# save this script to your computer as /etc/X11/Xsession.d/45custom_xrandr-settings:
# If an external monitor is connected, place it with xrandr
# External output may be "VGA" or "VGA-0" or "DVI-0" or "TMDS-1"
# More info at http://www.thinkwiki.org/wiki/Xorg_RandR_1.2
PRI_OUTPUT="DVI-0";
SEC_OUTPUT="DisplayPort-0";
SEC_LOCATION="left"; # SEC_LOCATION may be one of: left, right, above, or below
case "$SEC_LOCATION" in
left|LEFT)
SEC_LOCATION="--left-of $PRI_OUTPUT"
;;
right|RIGHT)
SEC_LOCATION="--right-of $PRI_OUTPUT"
;;
top|TOP|above|ABOVE)
SEC_LOCATION="--above $PRI_OUTPUT"
;;
bottom|BOTTOM|below|BELOW)
SEC_LOCATION="--below $PRI_OUTPUT"
;;
*)
SEC_LOCATION="--left-of $PRI_OUTPUT"
;;
esac
# Make and force resolution
myNewMode=$(cvt 1366 768 60 | grep -oP 'ModelineK.*') && #grep evrything after 'Modline'
myNewModeName="$(echo $myNewMode | grep -oP '"K[^"47]+(?=["47])' )" && #grep everything inside quotes
xrandr --newmode $myNewMode;
sleep 15;
xrandr --addmode $PRI_OUTPUT $myNewModeName;
# Activate secondary out (display port)
xrandr | grep $SEC_OUTPUT | grep " connected "
if [ $? -eq 0 ]; then
# xrandr --output $SEC_OUTPUT --auto $SEC_LOCATION
xrandr --output $PRI_OUTPUT --mode $myNewModeName --output $SEC_OUTPUT --auto $SEC_LOCATION
else
xrandr --output $PRI_OUTPUT --mode $myNewModeName --output $SEC_OUTPUT --off
fi
According to this at the Now automate it on login section, I have made my own script 45custom_xrandr-settings
and placed it into /etc/X11/Xsession.d/
. It works fine for me under Ubuntu 14.04 LTS. You could place the code below after the case
command described in that section.
PRI_OUTPUT="DVI-0";
# Make and force resolution
myNewMode=$(cvt 1366 768 60 | grep -oP 'ModelineK.*') && #grep evrything after 'Modline'
myNewModeName="$(echo $myNewMode | grep -oP '"K[^"47]+(?=["47])' )" && #grep everything inside quotes
xrandr --newmode $myNewMode;
sleep 15;
xrandr --addmode $PRI_OUTPUT $myNewModeName;
I believe that the above is what you are looking for. You can see the available outputs simply by running the xrandr
command. The outputs may be VGA
, VGA-0
, DVI-0
, TMDS-1
or DisplayPort-0
.
Here is the complete script that I made.
# To configure xrandr automatically during the first login,
# save this script to your computer as /etc/X11/Xsession.d/45custom_xrandr-settings:
# If an external monitor is connected, place it with xrandr
# External output may be "VGA" or "VGA-0" or "DVI-0" or "TMDS-1"
# More info at http://www.thinkwiki.org/wiki/Xorg_RandR_1.2
PRI_OUTPUT="DVI-0";
SEC_OUTPUT="DisplayPort-0";
SEC_LOCATION="left"; # SEC_LOCATION may be one of: left, right, above, or below
case "$SEC_LOCATION" in
left|LEFT)
SEC_LOCATION="--left-of $PRI_OUTPUT"
;;
right|RIGHT)
SEC_LOCATION="--right-of $PRI_OUTPUT"
;;
top|TOP|above|ABOVE)
SEC_LOCATION="--above $PRI_OUTPUT"
;;
bottom|BOTTOM|below|BELOW)
SEC_LOCATION="--below $PRI_OUTPUT"
;;
*)
SEC_LOCATION="--left-of $PRI_OUTPUT"
;;
esac
# Make and force resolution
myNewMode=$(cvt 1366 768 60 | grep -oP 'ModelineK.*') && #grep evrything after 'Modline'
myNewModeName="$(echo $myNewMode | grep -oP '"K[^"47]+(?=["47])' )" && #grep everything inside quotes
xrandr --newmode $myNewMode;
sleep 15;
xrandr --addmode $PRI_OUTPUT $myNewModeName;
# Activate secondary out (display port)
xrandr | grep $SEC_OUTPUT | grep " connected "
if [ $? -eq 0 ]; then
# xrandr --output $SEC_OUTPUT --auto $SEC_LOCATION
xrandr --output $PRI_OUTPUT --mode $myNewModeName --output $SEC_OUTPUT --auto $SEC_LOCATION
else
xrandr --output $PRI_OUTPUT --mode $myNewModeName --output $SEC_OUTPUT --off
fi
edited Oct 6 '15 at 2:44
kos
25.3k870119
25.3k870119
answered Sep 25 '15 at 12:15
ioaniatr
9614
9614
add a comment |
add a comment |
Create the file ~/.xprofile
and put your lines in it. It is ran at the beginning of the X user session.
1
this didnt work. commands fire up too early.
– neckTwi
May 27 '17 at 6:33
@neckTwi Thanks, I found thatxrandr --output ...
doesn't work but the previous two lines works. All in all this works for me.
– golopot
May 28 '17 at 5:45
add a comment |
Create the file ~/.xprofile
and put your lines in it. It is ran at the beginning of the X user session.
1
this didnt work. commands fire up too early.
– neckTwi
May 27 '17 at 6:33
@neckTwi Thanks, I found thatxrandr --output ...
doesn't work but the previous two lines works. All in all this works for me.
– golopot
May 28 '17 at 5:45
add a comment |
Create the file ~/.xprofile
and put your lines in it. It is ran at the beginning of the X user session.
Create the file ~/.xprofile
and put your lines in it. It is ran at the beginning of the X user session.
answered Feb 22 '17 at 23:00
golopot
1709
1709
1
this didnt work. commands fire up too early.
– neckTwi
May 27 '17 at 6:33
@neckTwi Thanks, I found thatxrandr --output ...
doesn't work but the previous two lines works. All in all this works for me.
– golopot
May 28 '17 at 5:45
add a comment |
1
this didnt work. commands fire up too early.
– neckTwi
May 27 '17 at 6:33
@neckTwi Thanks, I found thatxrandr --output ...
doesn't work but the previous two lines works. All in all this works for me.
– golopot
May 28 '17 at 5:45
1
1
this didnt work. commands fire up too early.
– neckTwi
May 27 '17 at 6:33
this didnt work. commands fire up too early.
– neckTwi
May 27 '17 at 6:33
@neckTwi Thanks, I found that
xrandr --output ...
doesn't work but the previous two lines works. All in all this works for me.– golopot
May 28 '17 at 5:45
@neckTwi Thanks, I found that
xrandr --output ...
doesn't work but the previous two lines works. All in all this works for me.– golopot
May 28 '17 at 5:45
add a comment |
There's a way of doing that declaratively. I think it's much better.
Create a new file 90-monitor.conf
:
Path: /usr/share/X11/xorg.conf.d/90-monitor.conf
Content:
Section "Monitor"
Identifier "VGA1"
Modeline "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
EndSection
Section "Screen"
Identifier "Screen0"
Monitor "Monitor-VGA1"
DefaultDepth 24
SubSection "Display"
Depth 24
Modes "1368x768_60.00"
EndSubSection
EndSection
add a comment |
There's a way of doing that declaratively. I think it's much better.
Create a new file 90-monitor.conf
:
Path: /usr/share/X11/xorg.conf.d/90-monitor.conf
Content:
Section "Monitor"
Identifier "VGA1"
Modeline "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
EndSection
Section "Screen"
Identifier "Screen0"
Monitor "Monitor-VGA1"
DefaultDepth 24
SubSection "Display"
Depth 24
Modes "1368x768_60.00"
EndSubSection
EndSection
add a comment |
There's a way of doing that declaratively. I think it's much better.
Create a new file 90-monitor.conf
:
Path: /usr/share/X11/xorg.conf.d/90-monitor.conf
Content:
Section "Monitor"
Identifier "VGA1"
Modeline "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
EndSection
Section "Screen"
Identifier "Screen0"
Monitor "Monitor-VGA1"
DefaultDepth 24
SubSection "Display"
Depth 24
Modes "1368x768_60.00"
EndSubSection
EndSection
There's a way of doing that declaratively. I think it's much better.
Create a new file 90-monitor.conf
:
Path: /usr/share/X11/xorg.conf.d/90-monitor.conf
Content:
Section "Monitor"
Identifier "VGA1"
Modeline "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
EndSection
Section "Screen"
Identifier "Screen0"
Monitor "Monitor-VGA1"
DefaultDepth 24
SubSection "Display"
Depth 24
Modes "1368x768_60.00"
EndSubSection
EndSection
answered Jan 2 at 0:19
Paulo Romeira
1012
1012
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f637911%2fhow-to-run-xrandr-commands-at-startup-in-ubuntu%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Hi Udhaya Kumar did you notice you have an answer? Please let me know if you manage.
– Jacob Vlijm
Jun 18 '15 at 16:48