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

Script to switch between 2 resolutions

I'm fairly new to OSX (bought my first MAC last summer)


I find myself switching between 2 resolutions on my retina MacBook Pro.

I use 1920x1080 at work (professionaly, I run Windows8 in Fusion6 to manage the IT infrastructure) and 1280x720 at home (in the couch, with half an eye on the TV)


To switch between these 2 resolutions, I do the following steps

- CMD+SPACE

- type "display"

- ENTER

- use the mouse to switch to another resolution

- press OK


Wouldn't it be easyer if I had 1 program that:

- switches to 1920x1080 if the current resolution is 1280x720

- switches to 1280x720 if the current resolution is 1920x1080


A "shortcut" (or whatever it's called in OSX) on the desktop, or even with a key-combination would be great.


Any insights?

MacBook Pro (Retina, Mid 2012), OS X Mountain Lion (10.8.2), 16GB 256SSD w/ VMwareFusion

Posted on Sep 10, 2013 11:42 AM

Reply
20 replies

Jan 14, 2017 5:11 AM in response to Kingster21

Hi Kingster 🙂 Searched a bit how to contact you, but didn't find any e-mail or anything else ... hopefully you'll get a message that someone replied to you here ...


Anyway, the original script doesn't work anymore on my new late-2016 Macbook Pro.


It errors out with the following message:


error "System Events got an error: Can’t get radio group 1 of group 1 of tab group 1 of window \"Built-in Retina Display\" of process \"System Preferences\". Invalid index." number -1719 from radio group 1 of group 1 of tab group 1 of window "Built-in Retina Display" of process "System Preferences"

Sep 10, 2013 4:38 PM in response to GeertCu

Maybe you might want to try the following script. Before using the script, you must enable access for assistive devices in the Accessibility System Preference pane. To use the script, just copy and paste it into the AppleScript Editor window, then click the Run button.



set resolution1 to "1920 × 1080"

set resolution2 to "1280 × 720"


tell application "Finder" to set {a, b, c, d} to bounds of window of desktop

set currentResolution to (c as text) & " × " & d


if currentResolution is resolution1 then

set newResolution to resolution2

else

set newResolution to resolution1

end if


tell application "System Preferences"

-- activate -- only if you wish to see the System Preferences window

reveal pane id "com.apple.preference.displays"

tell application "System Events"

tell process "System Preferences"

tell window 1

tell tab group 1

clickradio button 1

clickradio button 4

tell table 1 of scroll area 1

select (row 1 whose value of text field 1 is newResolution)

end tell

end tell

end tell

end tell

end tell

quit

end tell

Sep 12, 2013 4:24 AM in response to Pierre L.

That didn't work.


This does 🙂


local index1, index2, index3


set index1 to 3 -- 1440 x 900 (Best for Retina)

set index2 to 5 -- 1920 x 1200 (More Space)


-- Launch "System Preferences", open the "Displays" options and change to the "Display" tab

tell application "System Preferences"


activate

set the current pane to pane id "com.apple.preference.displays"

reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays"

end tell


local indexToUse


-- Now lets make the necessary changes

tell application "System Events"

tell window "Color LCD" of application process "System Preferences" of application "System Events"

tell tab group 1



-- Click the "Scaled" radio button


clickradio button "Scaled"


tell radio group 1 of group 1


-- Depending on what scale option/index is current selected, set the appropriate new option/index to use

if (value of radio button index1) is true then

set indexToUse to index2

else if (value of radio button index2) is true then

set indexToUse to index1

end if



-- Click the radio button for the new scale option/index


clickradio buttonindexToUse

end tell


end tell



-- If option/index 1 is selected a warning prompt is displayed, click the OK button to dismiss the prompt

if indexToUse = 1 then


clickbutton "OK" of sheet 1

end if

end tell

end tell


-- Quit "System Preferences"

quit application "System Preferences"


It works, but it is painfully slow 😟

Sep 12, 2013 7:06 AM in response to GeertCu

GeertCu wrote:


That didn't work.


Could you be a little more explicit? Is there any error message?


The script works flawlessly on my MacBook Pro under OS X 10.8.4, with the following values:


set resolution1 to "1440 × 900"

set resolution2 to "1280 × 800"


Have you enabled access for assistive devices in the Accessibility System Preference pane?


Message was edited by: Pierre L.

Sep 12, 2013 7:45 AM in response to GeertCu

GeertCu wrote:


That didn't work.


Does the following improved version work?


set resolution1 to "1920 × 1080" -- if that resolution exists on your monitor

set resolution2 to "1280 × 720" -- if that resolution exists on your monitor


tell application "Finder" to set {a, b, c, d} to bounds of window of desktop

set currentResolution to (c as text) & " × " & d


if currentResolution is resolution1 then

set newResolution to resolution2

else

set newResolution to resolution1

end if


tell application "System Preferences"

activate-- only if you wish to see the System Preferences window

set current pane to pane id "com.apple.preference.displays"

reveal anchor "displaysDisplayTab" of current pane

tell application "System Events"

tell process "System Preferences"

tell window 1

tell tab group 1

clickradio button "Scaled"

tell table 1 of scroll area 1

select (row 1 whose value of text field 1 is newResolution)

end tell

end tell

end tell

end tell

end tell

quit

end tell

Sep 13, 2013 2:16 PM in response to GeertCu

At this point, I can see only two explanations why the script doesn't work:


1) A short delay is needed before telling table 1 to select a row, like this:


clickradio button "Scaled"

repeat until table 1 of scroll area 1 exists

end repeat

tell table 1 of scroll area 1

select (row 1 whose value of text field 1 is newResolution)

end tell


2) Maybe your Color LCD window is not exactly the same as mine:


User uploaded file


If such is the case, I can't help you.

Oct 23, 2013 2:51 AM in response to GeertCu

I haven't downloaded Mav yet, so this is just extrapolation, but <class pcap> should be the code for application process in System Event's scripting dictionary. Check the scripting dictionary to make sure that they haven't for some odd reason removed that term (it should be in the processes suite), and if it's still there in the dictionary, delete and retype the phrase in the script. That forces the script to reread the terminology rather than relying on the previously compiled code.

Oct 26, 2013 12:30 AM in response to GeertCu

@GeertCu: I had the same problem. I had to change "Color LCD" to "Built-in Retina Display". Here's my script to switch resolution between retina and more space:


tell application "System Preferences"

reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"

end tell



tell application "System Events" to tell process "System Preferences" to tell window "Built-in Retina Display"

click radio button "Display" of tab group 1

click radio button "Scaled" of radio group 1 of tab group 1

tell radio group 1 of group 1 of tab group 1

set isRetinaOptimized to get value of radio button 3

end tell

if isRetinaOptimized then

click radio button 5 of radio group 1 of group 1 of tab group 1

else

click radio button 3 of radio group 1 of group 1 of tab group 1

end if

end tell

quit application "System Preferences"

Oct 31, 2013 1:08 AM in response to GeertCu

GeertCu,


You seem to go from Built-in Retina Display to Scaled directly, while it first needs to select the "Display" tab group.

See my script:


tell application "System Events" to tell process "System Preferences" to tell window "Built-in Retina Display"

click radio button "Display" of tab group 1

click radio button "Scaled" of radio group 1 of tab group 1


First it selects Built-in Reinta Display, then it clicks the "Display" tab, THEN it clicks "Scaled"

Oct 31, 2013 1:46 AM in response to GeertCu

Hi GeertCu,


Sure:


tell application "System Preferences"

reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"

end tell



tell application "System Events" to tell process "System Preferences" to tell window "Built-in Retina Display"

click radio button "Display" of tab group 1

click radio button "Scaled" of radio group 1 of tab group 1

tell radio group 1 of group 1 of tab group 1

set isRetinaOptimized to get value of radio button 3

end tell

if isRetinaOptimized then

click radio button 5 of radio group 1 of group 1 of tab group 1

else

click radio button 3 of radio group 1 of group 1 of tab group 1

end if

end tell

quit application "System Preferences"

Oct 31, 2013 2:13 AM in response to GeertCu

Next up ...


It would be _very_ nice to have something like this:


At work I use the 1080p resolution, and at home in the couch I use the "best for retina" resolution.

The script above switched _very_ easy between those 2 resolutions.


But what if it would automatically switch - or even better "semi-automatically"...


At home I have an Apple Airport in the 10.0.1.0/24 subnet, with 10.0.1.1 as gateway via DHCP. At work it's 172.16.0.0/23 with gateway 172.16.0.254. I'm sure we can use that to information to do the following.


Automated version:


- computer wakes from sleep

- connects to WIFI

- checks the default getaway

- if it is home > set retina resolution

- if it is work > set 1080p resolution


Semi-automated version:


- use the OSX Notification center with a custom alert "hey, you're at home, I'm gonna switch your resolution, if you don't want it, press "cancel" in the notification"


That would be Awesome with a capital A.

Script to switch between 2 resolutions

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