I use different screen resolutions based on the activity I'm doing during the day.
For example when I'm coding I prefer to have more space available.
Is it possible to associate a keyboard shortcut to change the scaled display resolution ?
(see the attached screenshot)
11 Answers
Yes you totally can achieve this without running additional apps. On my system I created two different scripts. One script for adjusting the display resolution higher and one adjusting display resolution lower. On my system I just enabled both scripts as dictation commands but if you create a new Service through Automator, you can assign keyboard shortcuts to those services..
First, here are the two scripts I started with.
This one is for making the display resolution higher: if my display resolution is already at the default position
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 "Scaled" of radio group 1 of tab group 1
click radio button 4 of radio group 1 of group 1 of tab group 1
end tell
quit application "System Preferences"
Running that script will result in this:
This next script is for making the display resolution lower: if my display resolution is not set at the default setting
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 "Scaled" of radio group 1 of tab group 1
click radio button 3 of radio group 1 of group 1 of tab group 1
end tell
quit application "System Preferences"
Once I made sure both scripts work correctly, I then opened up Automator and created a new service for the display resolution higher and added the appropriate script as shown in the following image. I saved this file as rez_higher.workflow
From here, I opened up system preferences/keyboard/shortcuts/services. I located that new service I created and assigned it a keyboard shortcut
After this, just follow the same procedures to create a new workflow and service for the display resolution lower
UPDATE: On OS Ventura, System Preferences.app is now System Settings.app so all of the code above will not work. However, this following AppleScript code will work.
try
if application "System Settings" is running then ¬
do shell script "killall 'System Settings'"
end try
repeat until application "System Settings" is not running
delay 0.1
end repeat
tell application "System Settings"
reveal anchor "resolutionSection" of ¬
pane id "com.apple.Displays-Settings.extension"
end tell
tell application "System Events" to tell process "System Settings"
repeat until exists of table 1 of scroll area 1 of group 1 of scroll area 2 ¬
of group 1 of group 2 of splitter group 1 of group 1 of window "Displays"
delay 0.1
end repeat
-- row 3 on my MBP is 1440 x 900
set selected of row 3 of table 1 of scroll area 1 of group 1 of scroll area 2 ¬
of group 1 of group 2 of splitter group 1 of group 1 of window ¬
"Displays" to true
end tell
tell application "System Settings" to quit
-
1
-
1This is amazing. I follow most of it. Where can one find details such the name of the anchor being 'displayDisplayTab'? I'd like to develop something similar to set (and unset) the desktop color. All/any details are very welcome. Dec 20, 2019 at 17:03
-
2That script in example is thrown error:
error "System Events got an error: Can’t get tab group 1 of window \"Built-in Retina Display\" of process \"System Preferences\". Invalid index.
Is it broken by any OSX update? Jan 22, 2020 at 21:08 -
1
-
Thank you SO MUCH to wch1zpink and @Zade! This is exactly what I was hoping for! I will use this 10+ times/day because whenever I screenshare with coworkers, I need to use a lower resolution.– RyanNov 19, 2020 at 16:39
I wrote the free command line tool displayplacer to change resolutions/rotations for single or multi-monitor desktops. You can trigger a "profile" (example below) via a keyboard shortcut with Automator like wch1zpink explained, BetterTouchTool, etc.
displayplacer 'id:69731906 res:1440x900 scaling:on origin:(0,0) degree:0'
-
F A N T A S T I C ! ! ! ! I was searching for something like that for ages. THANKS!– DuckJan 16 at 16:31
-
F A N T A S T I C ! ! ! ! ++ the only solution that works [for me] in Ventura 13.2.1– smingMar 23 at 13:25
-
-
Could you explain the command in the answer (what is id for example, does it change per display)? Is it possible to ask for a higher / lower resolution with it?– SampoAug 25 at 6:37
-
@sampo Each display has a unique ID, yes you can alter the resolution to be higher or lower. You can alter all of the options shown. There are instructions in the README.md of the displayplacer repo that show how to list all of the options available with the program. Aug 31 at 14:51
Proposed Fix for Zade's change for the Browser UI System Preferences in 13.0.1, the Shortcut didn't work anymore for me in Ventura 13.2 because of an error around the value of attribute "AXAttributedDescription"
part
What I use in Ventura 13.2 now:
do shell script "open x-apple.systempreferences:com.apple.preference.displays"
tell application "System Events"
tell application process "System Settings"
repeat until (exists UI element 1 of group 1 of scroll area 2 of group 1 of group 2 of splitter group 1 of group 1 of window 1)
delay 0.1
end repeat
tell window 1 #"Displays"
set displayOptions to UI element 1 of group 1 of scroll area 2 of group 1 of group 2 of splitter group 1 of group 1
set StandardRes to button 4 of displayOptions
set MoreSpaceRes to button 5 of displayOptions
if focused of StandardRes is false then
click StandardRes
else
click MoreSpaceRes
end if
end tell
end tell
end tell
quit application "System Settings"
This switches between the Standard resolution and the "More Space" one ("Mehr Fläche" in German) and should be system language independent.
Fix for wch1zpink's answer on macOS 13.0.1, thanks to the UI Browser app:
do shell script "open x-apple.systempreferences:com.apple.preference.displays"
tell application "System Events"
tell application process "System Settings"
repeat until (exists UI element 1 of group 1 of scroll area 2 of group 1 of group 2 of splitter group 1 of group 1 of window "Displays")
delay 0.1
end repeat
tell window "Displays"
set displayOptions to UI element 1 of group 1 of scroll area 2 of group 1 of group 2 of splitter group 1 of group 1
set theButton to (first button of displayOptions whose value of attribute "AXAttributedDescription" contains "Selected")
if help of theButton is "2560 × 1440" then
click button 1 of displayOptions
else
click button 3 of displayOptions
end if
end tell
end tell
end tell
quit application "System Settings"
Fix on macOS 12.0.1:
tell application "System Preferences"
reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
end tell
tell application "System Events"
tell application process "System Preferences"
repeat until (exists radio button "Scaled" of radio group 1 of group 1 of window "Displays")
delay 0.1
end repeat
tell window "Displays"
set isScaled to value of radio button "Scaled" of radio group 1 of group 1
if isScaled = 0 then
click radio button "Scaled" of radio group 1 of group 1
click button 1 of UI element 3 of group 1
else
click radio button "Default for display" of radio group 1 of group 1
end if
end tell
end tell
end tell
quit application "System Preferences"
Fix on macOS 10.15.4:
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"
set isScaled to value of radio button "Scaled" of tab group 1
if isScaled = 0 then
click radio button "Scaled" of tab group 1
click radio button 1 of radio group 1 of group 1 of tab group 1
else
click radio button "Default for display" of tab group 1
end if
end tell
quit application "System Preferences"
-
I still have the same error. error
System Events got an error: Can’t get radio button \"Scaled\" of tab group 1 of window \"Built-in Retina Display\" of process \"System Preferences\"." number -1728 from radio button "Scaled" of tab group 1 of window "Built-in Retina Display" of process "System Preferences"
With the prior code, the number is 1719. Just changed the number– leonJul 3, 2020 at 17:29 -
@leon use the UI Browser app to get the name of the buttons in your version of macOS.– ZadeNov 1, 2021 at 18:38
-
It works fantastic (Ventura version); however, how can I modify it to set it for a build-in-display only when I have an external monitor connected?
error "System Events got an error: Can’t get button 3 of static text \"Use as\" of group 1 of scroll area 2 of group 1 of group 2 of splitter group 1 of group 1 of window \"Displays\" of application process \"System Settings\". Invalid index." number -1719 from button 3 of static text "Use as" of group 1 of scroll area 2 of group 1 of group 2 of splitter group 1 of group 1 of window "Displays" of application process "System Settings"
Thanks! Mar 27 at 14:31
What works for me in 2022 on macOS 12.1 on MacBook Pro
To have a single keyboard shortcut that toggles between 2 resolutions:
- Automator > File > New > Quick Action > Choose
- Search for "Run AppleScript" and double-click the result.
- Replace the default script code with what I provide below.
- Try clicking the Run button a couple times to see if the toggling works.
- Save as "toggle_display_resolution". (Later, if you ever want to edit it, you'll open
/Users/your_username/Library/Services/toggle_display_resolution.workflow
in Automator). - Close Automator.
- System Preferences > Keyboard > Shortcuts > Services
- Assign a keyboard shortcut to the new service that you created (which will probably be at the bottom of the list).
By the way, you may need to edit your "Security & Privacy" > Accessibility. See answer.
on run {input, parameters}
# https://apple.stackexchange.com/a/436069/53510
tell application "System Preferences"
reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
end tell
tell application "System Events"
tell application process "System Preferences"
repeat until (exists radio button "Scaled" of radio group 1 of group 1 of window "Displays")
delay 0.1
end repeat
tell window "Displays"
set isScaled to value of radio button "Scaled" of radio group 1 of group 1
if isScaled = 0 then
click radio button "Scaled" of radio group 1 of group 1
# button '5' means highest resolution (smalled font):
click button 5 of UI element 3 of group 1
else
click radio button "Default for display" of radio group 1 of group 1
end if
end tell
end tell
end tell
# The next line is optional and could be commented out by prepending with a hash (#).
quit application "System Preferences"
return input
end run
P.S. Many thanks to wch1zpink and Zade, whose answers led to mine. Upvote theirs too.
P.P.S. I'm curious to learn whether I could more easily share this Quick Action / Service.
-
1
Oct 2022 macOS 12.6 Solution
Adding another solution to the list. Imron Gamidli's solution got me the closest to what I wanted with the toggle behavior.
Here is my script which I've added as a Raycast command so that I can trigger from raycast or assign a keyboard shortcut.
#!/usr/bin/osascript
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Toggle Resolution
# @raycast.mode silent
# Optional parameters:
# @raycast.icon 🤖
set monitor to 2
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.displays"
delay 2
tell application "System Events"
tell window "Displays" of application process "System Preferences"
click button "Display Settings…"
delay 2
click row monitor of outline 1 of scroll area 1 of sheet 1
click radio button "Scaled" of radio group 1 of sheet 1
try
set selected_button to button "Resolution5, Selected" of UI element 6 of sheet 1
click button "Resolution1" of UI element 6 of sheet 1
on error
click button "Resolution5" of UI element 6 of sheet 1
end try
delay 0.5
click button "Done" of sheet 1
end tell
end tell
end tell
# The next line is optional and could be commented out by prepending with a hash (#).
delay 2
quit application "System Preferences"
-
Thanks for sharing this since my answer apple.stackexchange.com/a/436069/53510 doesn't work anymore. I can't get your answer working either. Syntax Error: System Events go an error: Can't get button "Resolution5" of UI element 6 of sheet 1 of window "Displays" of application process "System Preferences".– RyanOct 31, 2022 at 14:45
-
@Ryan What os version are you on? This is working for me on 12.6 and the only version I've tested it on. I have noticed some issues occasionally, I think when the machine is under load. You can try playing with the delays and see if a longer delay helps. Nov 2, 2022 at 19:29
-
Thanks. I'm on 12.6. Today I see that I'm eligible to download 13.0, so maybe I'll try upgrading within a week or so. Even with longer delays, I'm still getting the error I mentioned in my previous comment. Out of curiosity, how did you know how to write this script? How can I figure out the names and numbers of each area / element on the screen? Thanks!!– RyanNov 2, 2022 at 20:07
-
1@Ryan Hmm, not sure then. Its still working on my machine. I would guess that 13.0 will break the script as there was a redesign of the System Preferences renaming it to System Settings and redesigning it. As far as how to write the script, I'm super inexperienced in apple script. I tried a bunch of the options here, guessed alot, search the automators forum, and found that you can get some of the element names through the Accessibility Inspector tool. There is some breakpoint and logging support too you can use to print out elements. If anyone else has advice here, I'm also keen to learn. Nov 3, 2022 at 18:53
-
As of macOS 12.2.1 with the introduction of Shortcuts, you no longer need a keyboard shortcut anymore. Anyway, many thanks to Ryan who provided the basis of my code. Here it goes:
on run {input, parameters}
# https://apple.stackexchange.com/a/436069/53510
tell application "System Preferences"
activate
reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
delay 2 #Make longer if needed
tell application "System Events"
tell application process "System Preferences"
tell window 1
click button 1 #Monitor settings
delay 0.7 #Make longer if needed
select row 2 of outline 1 of scroll area 1 of sheet 1 #Row=monitor number
click radio button 2 of radio group 1 of sheet 1 #Select "Scaled"
click button 2 of UI element 6 of sheet 1 #Select resolution
click button 2 of sheet 1 #Done
click button 4 #Close System Preferences
end tell
end tell
end tell
end tell
return input
end run
Delays are needed because of window opening time, otherwise the indexing breaks. If it still breaks, just extend the delays. For the row number, if you want to influence your e.g. 3rd monitor, write "row 3" instead. If you're making a second one to increase your resolution and scaled is thus already selected, you can get rid of that line.
EDIT: for MacOS 12.3, change button 4 to button 5
This worked for me on Monterey 12.3.1 to change resolution on my 2nd monitor from the list. I will transfer this script to automator to change resolution with keyboard
set res to 3
set monitor to 2
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.displays"
delay 2
tell application "System Events"
tell window "Displays" of application process "System Preferences"
click button "Display Settings…"
delay 2
click row monitor of outline 1 of scroll area 1 of sheet 1
click radio button "Scaled" of radio group 1 of sheet 1
click button res of UI element 6 of sheet 1
end tell
end tell
end tell
-
Thanks for sharing this since my answer apple.stackexchange.com/a/436069/53510 doesn't work anymore. I can't get your answer working either. Syntax Error: System Events go an error: Can't get button 3 of UI element 6 of sheet 1 of window "Displays" of application process "System Preferences". Invalid index.– RyanOct 31, 2022 at 14:47
You can use this app called SwitcherResX (http://www.madrau.com/srx_download/download.html) where they have option to change resolution with Keyboard shortcut or based on application you use. They have a trial to try.
-
Thanks. I was looking for something at system level without running additional apps. But I will keep your suggestion in consideration as alternative solution!– david-eDec 1, 2016 at 18:26
The application EasyRes (free in the Apple app store) did it for me. I had spent an hour resetting the NVRAM, trying frantically to get my 2006-vintage 30" Apple Cinema display back to full resolution, to no avail. I must have rebooted 25 times. EasyRes took care of it. Thank you EasyRes, I was going nuts!
Update: this is not "sticky" -- when I reboot, I'm back to 1280x800 and I have to use EasyRes again, but I reboot only ever couple of months, so this is workable.
Anyone have an AppleScript for Ventura? Tried to use Keyboard Maestro and somehow can't get this going. Have a few apps that don't have font resize as an option and I'd love a quick way to do this and set it back to default fast.
-
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review– agarzaNov 26, 2022 at 17:09
Note @wch1zpink's answer works great, but Big Sur makes some breaking changes to it and requires revisions. This worked for me with an external display so just replace LG ULTRAWIDE with the title on the window.
compress-screen
on run {input, parameters}
activate application "System Preferences"
tell application "System Events"
tell process "System Preferences"
click button "Displays" of scroll area 1 of window "System Preferences"
delay 0.5
tell tab group 1 of window "LG ULTRAWIDE"
click radio button "Scaled"
delay 0.5
select row 4 of table 1 of scroll area 1
end tell
end tell
delay 1
quit application "System Preferences"
end tell
return input
end run
expand-screen
on run {input, parameters}
activate application "System Preferences"
tell application "System Events"
tell process "System Preferences"
click button "Displays" of scroll area 1 of window "System Preferences"
delay 0.5
tell tab group 1 of window "LG ULTRAWIDE"
click radio button "Default for Display"
end tell
end tell
delay 0.5
quit application "System Preferences"
end tell
return input
end run
/path/to/display_manager.py res 1920 1080 60
)