Cory G.
Cory G.

Reputation: 1587

Script to change screen resolution and run a program?

I have never done any scripting (and am rather new to Linux as well). What I would like is an icon that the user can click on that does the following things:
1. Change the screen resolution to 640x480.
2. Run a program (let's call it /path/myprogram)
3. When the program terminates, change the screen resolution back to 1024x768.

Apparently there is something called "xrandr" which might be able to do this, but I'm not sure how it works. Also, the screen is set to "upside down" right now, and should stay that way throughout (I don't know if that is important for this script or not).

Also, I've noticed that in Ubuntu, when clicking on scripts, it brings up a prompt: "Run in Terminal", "Display", "Run", etc. Is there some way to make it default to "Run" so that this prompt is not displayed at all?

Thank you very much.

[[EDIT]]

I made a script using xrandr and it works...almost. It does not behave the same as going to Preferences -> Monitors. When I use the script to change to 640x480, part of the right side of the screen gets cut off. Also, it changes the refresh rate to 73Hz instead of 60Hz for some reason (and if I try changing the refresh rate to 60Hz from Preferences afterwards, the image becomes a bit distorted).

I tried using xrandr --prop to figure out what is happening, and the only difference between the regular Preferences -> Monitors way and the xrandr way appears to be this line:

   640x480        72.8     75.0     60.0* 
   640x480        72.8*    75.0     60.0  

The heading for that section is (I think it's a heading?):

VGA1 connected 640x480+0+0 inverted (normal left inverted right x axis y axis) 0mm x 0mm

The numbers seem like they would correspond to the refresh rate, but that doesn't explain why the image is getting cut off/distorted.

So basically, I have no idea what's going on and no idea how to fix it. I need the resolution change to behave the same as Preferences -> Monitors.

Also, as far as the desktop icon goes, it turns out that Ubuntu has something called a "Launcher" and that worked nicely. Thank you anyway. :)

Upvotes: 2

Views: 9181

Answers (1)

Mikel
Mikel

Reputation: 25596

Resizing the screen:

xrandr --size 640x480

Desktop icon:

[Desktop Entry]
Encoding=UTF-8
Name=My App
Comment=What the app does
Exec=programname
Icon=??
Terminal=false
Type=Application
StartupNotify=true
Categories=??

and put it in ~/.local/share/applications/programname.desktop or /usr/share/applications/programname.desktop.

See Desktop Entry Specification and Desktop Entry Files for full details.

Upvotes: 8

Related Questions