I'm using Ubuntu 14.04 and I wish to force a specific program to run at a predetermined screen resolution and have the screen return to my default resolution after closing the program. The program is the Brackets text editor and the extensions manager is not shown completely when I run Brackets at 1024*768, as seen below in the picture.

Extensions manager truncated due to screen resolution

It displays well at 1280*1024 but it is very uncomfortable to my eyes.

Here is my xrandr command output:

Screen 0: minimum 8 x 8, current 1024 x 768, maximum 32767 x 32767
VGA1 connected primary 1024x768+0+0 (normal left inverted right x axis y axis) 340mm x 255mm   
   1600x1200      74.8      
   1280x1024      85.0     75.0      
   1024x768       85.0     75.1*    70.1     60.0      
   1024x768i      87.1     
   832x624        74.6      
   800x600        85.1     72.2     75.0     60.3     56.2      
   640x480        85.0     75.0     72.8     66.7     60.0               
   720x400        87.8     70.1   
VIRTUAL1 disconnected (normal left inverted right x axis y axis)
  • Please explain with more details the case, why do you need to do that? – shaddy Apr 6 '15 at 12:14
  • 1
    could you mention the program in question, the output of xrandr and the desired resolution? – Jacob Vlijm Apr 6 '15 at 12:49
  • Just edited my question ! – Misho21 Apr 6 '15 at 13:53
  • I know that brackets is build mainly with html and css .. if just I can hack the code and edit it that will be another way to do it but I don't know how to start – Misho21 Apr 6 '15 at 14:16

You can use the following python script to start your application at a given resolution:

#!/usr/bin/env python3

import argparse
import re
import subprocess
import sys

parser = argparse.ArgumentParser()
parser.add_argument('--output', required=True)
parser.add_argument('--resolution', required=True)
args = parser.parse_args()

device_context = ''    # track what device's modes we are looking at
modes = []             # keep track of all the devices and modes discovered
current_modes = []     # remember the user's current settings

# Run xrandr and ask it what devices and modes are supported
xrandrinfo = subprocess.Popen('xrandr -q', shell=True, stdout=subprocess.PIPE)
output = xrandrinfo.communicate()[0].decode().split('\n')

for line in output:
    # luckily the various data from xrandr are separated by whitespace...
    foo = line.split()

    # Check to see if the second word in the line indicates a new context
    #  -- if so, keep track of the context of the device we're seeing
    if len(foo) >= 2:  # throw out any weirdly formatted lines
        if foo[1] == 'disconnected':
            # we have a new context, but it should be ignored
            device_context = ''
        if foo[1] == 'connected':
            # we have a new context that we want to test
            device_context = foo[0]
        elif device_context != '':  # we've previously seen a 'connected' dev
            # mode names seem to always be of the format [horiz]x[vert]
            # (there can be non-mode information inside of a device context!)
            if foo[0].find('x') != -1:
                modes.append((device_context, foo[0]))
            # we also want to remember what the current mode is, which xrandr
            # marks with a '*' character, so we can set things back the way
            # we found them at the end:
            if line.find('*') != -1:
                current_modes.append((device_context, foo[0]))

for mode in modes:
    if args.output == mode[0] and args.resolution == mode[1]:
        cmd = 'xrandr --output ' + mode[0] + ' --mode ' + mode[1]
        subprocess.call(cmd, shell=True)
    print('Unable to set mode ' + args.resolution + ' for output ' + args.output)

subprocess.call(args.APP, shell=True)

# Put things back the way we found them
for mode in current_modes:
    cmd = 'xrandr --output ' + mode[0] + ' --mode ' + mode[1]
    subprocess.call(cmd, shell=True)

Save the above script (e.g as my-script.py) and make it executable:

chmod +x my-script.py

To set a resolution of 1280x1024 and start gedit just type:

./my_script.py --output VGA1 --resolution 1280x1024 gedit

To avoid typing this command everytime, save the script in your home directory and add the following lines to your .bashrc:

alias my_bracket='~/my_script.py --output VGA1 --resolution 1280x1024 gedit'

Or even better, modify the desktop file that the package installs in /usr/local/share/applications/brackets.desktop.

sudo gedit /usr/local/share/applications/brackets.desktop

And replace the file content with the new lines below:

[Desktop Entry]
Exec=/home/mushir/my_script.py --output VGA1 --resolution=1280x1024 /opt/brackets/brackets

Source: Checkbox xrandr_cycle script

  • thanks .. but there is two issues about this script : every time I need to run this command and this not very convenient for me and after I close the program my screen doesn't go back automatically to the default resolution – Misho21 Apr 6 '15 at 14:07
  • @Misho21: I've fixed the settings recovery issue – Sylvain Pineau Apr 6 '15 at 14:27
  • 1
    thanks now it's working ! I wonder if there is away to start this script automatically every time I run the program so it won't be necessary to run it from terminal every time ? – Misho21 Apr 6 '15 at 14:33
  • 1
    @Misho21: Forget the (home) .bashrc update and prefer the .desktop if you're not starting brackets from a terminal – Sylvain Pineau Apr 6 '15 at 15:10
  • 1
    @Misho21: You can't, plymouth operates earlier in the boot process and uses itw own configuration files. – Sylvain Pineau Apr 6 '15 at 15:33

Not using ubuntu here (Gentoo person), but look for package xrandr. Usually you can use things like

xrandr --output VGA-1 --mode 640x480

to change resolution and

xrandr --output VGA-1 --preferred

will put you back to default resolution.


without options will give you display names and resolutions.

Just saw previous script version also use xrandr :). But maybe you can still find the information useful. Read in the manual pages for option tweaking

man xrandr

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.