Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Script to change display resolution?

I would like to set the screen to a specific resolution when I login to a particular account and reset it when I log out. I have no idea where to start - don't see any method for changing values in System Preferences.

Mini - 1.42, Mac OS X (10.4.9), 1Gig (self installed)

Posted on Feb 25, 2008 7:54 PM

Reply
4 replies

Feb 25, 2008 8:15 PM in response to frankinmelrose

I wrote a script a long time ago that changed color depth and resolution. There wasn't then and isn't now a way to script many parts of System Preferences, including the Display Pane. It all had to be done with GUI Scripting. Here's the meat of the script without any changes made:

on SwitchPrefs(newColor, newRes)
tell application "System Events"
tell process "System Preferences"
tell tab group 1 of window 1
click radio button "Display"
tell group 1
tell pop up button 1
if value is not newColor then
click
click menu item newColor of menu "OtherViews"
end if
end tell
tell table 1 of scroll area 1
repeat with x from 1 to count of rows
if selected of row x is true then
set currentValue to value of text field 1 of row x
exit repeat
end if
end repeat
if currentValue is not newRes then
repeat with i from 1 to count of rows
if value of text field 1 of row i is newRes then
set selected of row i to true
exit repeat
end if
end repeat
end if
end tell
end tell
end tell
try
tell window 1 to click button "OK"
delay 1
tell window 1 to click button "Confirm"
end try
end tell
end tell
tell application "System Preferences" to quit
end SwitchPrefs



Also, some tips for opening System Preferences to the right spot can be found here:

http://www.apple.com/applescript/features/system-prefs.html

The script's ugly and thrown together. If it's not making any sense as is I can try to clarify.

Message was edited by: Jason Kacmarski

Feb 26, 2008 5:31 AM in response to frankinmelrose

01. Download and double click on ' cscreen.zip' (12 KB in size, freeware). 'cscreen' (56 KB in size) file will result.

-- One time installation procedure:
02. Launch 'Terminal' (in the '/Applications/Utilities/' folder).
03. Enter ...

open /usr/bin/

... and press the <return> key.
04. Drag 'cscreen' onto the opened 'bin' window. You will have to authenticate and enter an administrators' password to continue.
05. Close the 'bin' window.

-- Time to script.
06. Launch 'Script Editor' (in the '/Applications/AppleScript/' folder).
07. Copy the code below, and paste into the 'Script Editor' 'Untitled' window.

if (((word 16 of (do shell script "cscreen")) as number) ≠ 800) then
do shell script "cscreen -x 800 -y 600 -r 85"
else
do shell script "cscreen -x 1280 -y 1024 -r 85"
end if

... replacing the '800' of the first and second lines of code with the screen width you want at log in; replacing the '600' of the second line of code with the screen height you want at log in; replacing the '85' of the second line of code with the screen refresh rate you want at log in; and finally, replacing the '1280', '1024', and '85' with the desired respective screen width, screen height, and screen refresh rate you want at log out.
08. Save the code as an application.
09. Launch 'System Preferences' (in the '/Applications/' folder), click on 'Accounts', click on 'Login Items' tab.
10. Drag your created application onto the 'Login Items' list.

-- Example - if you want, at log in, the screen to be set to 1024 x 768 with a refresh rate of 100; and, at log out, the screen to be set to 800 x 600 with a refresh rate of 85 ...

if (((word 16 of (do shell script "cscreen")) as number) ≠ 1024) then
do shell script "cscreen -x 1024 -y 768 -r 100"
else
do shell script "cscreen -x 800 -y 600 -r 85"
end if
11. As far as 'when logging out'. You can drag the created application to the 'Dock' - where one can then click on the 'Dock' based application icon - to toggle the screen resolution; or, simply repeat Steps 06. through 10. for each account - this way the screen resolution is set as each account is logged in to.

-- Additional information.

-- Determining valid refresh rates for your Macs' monitor:
In 'Terminal' enter ...

cscreen -v

... and press the <return> key. Displayed in column form are the 'Index' (monitor number, '1' is typically - if only one monitor is in use), 'Depth' (8 = 256 colors, 16 = thousands of colors, 32 = millions of colors), 'Width' (screen width in pixels), 'Height' (screen height in pixels), and 'Refresh(Hz)' (screen refresh rate).

-- Disclaimer (?):
-- 'cscreen' continues to work through 'Tiger' (MacOS X 10.4.11). I have yet to try it on 'Leopard' (MacOS X 10.5.x).

Feb 26, 2008 5:56 AM in response to dev_sleidy

As noted in Step 11. above - if you create one application per log in account - then all you need is a single line of code.

For example - you have two (2) accounts 'A' and 'B'.

For 'A' (which will have a screen of 1024 x 768 at 100 Hz), log into 'A's account, create an application containing ...

if (((word 16 of (do shell script "cscreen")) as number) ≠ 1024) then do shell script "cscreen -x 1024 -y 768 -r 100"

..., and save the application (such as 'cscreen.app') in the '/Users/A/Documents/' folder. Do not forget to drag 'cscreen.app' to 'System Preferences' 'Accounts' 'Login Items' tabs' list.

For 'B' (which will have a screen of 800 x 600 at 85 Hz), log into 'B's account, create an application containing ....

if (((word 16 of (do shell script "cscreen")) as number) ≠ 800) then do shell script "cscreen -x 800 -y 600 -r 85"

..., and save the application (such as 'cscreen.app') in the '/Users/B/Documents/' folder. Do not forget to drag 'cscreen.app' to 'System Preferences' 'Accounts' 'Login Items' tabs' list.

Feb 26, 2008 7:15 AM in response to frankinmelrose

Thanks very much Jason and dev for your quick responses - I'm not going to be able to work on this for a couple of days, so I'm going to leave the thread open in case I have any questions. I'll report back.

(In case you're wondering, my objective is to set up a special account that I can VCN to my home Mac from a PC at work - so to speed up screen redrawing, etc, I want to be able to change the resolution on that account when I log in and then change it back to "normal" when I log out. I'll be using SSH with RSA authentication and tunnel the VCN through that - I've got SSH and VCN working - next step is to implement VCN tunneling through SSH).

(Just downloaded and ran quick test of csscreen - looks like a great little utility - too bad it seems to be an "orphan" - but then that lead me to BrowserShots, which seems just the thing for some QA I'm doing!)

Script to change display resolution?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.