macOS – Changing Display Resolution via Keyboard Shortcuts

applescriptmacmacos

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)
enter image description here

Best Answer

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

enter image description here

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:

enter image description here

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

enter image description here

From here, I opened up system preferences/keyboard/shortcuts/services. I located that new service I created and assigned it a keyboard shortcut

enter image description here

After this, just follow the same procedures to create a new workflow and service for the display resolution lower