Skip to content

Instantly share code, notes, and snippets.

@elit8888
Last active February 1, 2024 23:16
Show Gist options
  • Save elit8888/e3bf24fb477e13db0734c703b8226514 to your computer and use it in GitHub Desktop.
Save elit8888/e3bf24fb477e13db0734c703b8226514 to your computer and use it in GitHub Desktop.
Use keyboard shortcut to adjust resolution higher or lower in MacOS

Resolution Adjustment Shortcut Setup

This note illustrates how to adjust resolution using keyboard shorcut using built-in app automator. After setting up, I can use two actions:

  • Switch to Highest resolution
  • Switch to Default resolution

I'm new to apple script, so the rule is very simple.

References:

Tested on macOS 10.15.4, with MBP 2017, 13-inch. This is the screenshot of Display option in System Preference > Displays. Display option

Note: The actions will require the access of Accessibility. e.g., If you are using Safari and want to switch the resolution, then Safari need to gain access of Accessibility. Otherwise the actions will failed.

Switch to highest resolution

The script below switch the resolution to the highest, if it's the highest currently, nothing will changed.

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 tab group 1
	click radio button 4 of radio group 1 of group 1 of tab group 1
end tell
quit application "System Preferences"

You can test/adjust it via built-in Script Editor.

Switch to default resolution

The script below will switch the resolution to 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"
	tell tab group 1
		click radio button "Display"
		click radio button "Default for display"
	end tell
end tell
quit application "System Preferences"

Setup

Once tested, you can add them into Automator.

  1. First open Automator and select Service type, and then select the action Run AppleScript. Set Service receives to no input, and you can decide what application can use. Automator
  2. Then you can paste the code above into the script. You can then test it to see if it's working, it might first require the access of Accessibility.
  3. Save the workflow, then you will find the option with the name you just saved in System Preference > Keyboard > Shorcuts Tab > Services > General. keyboard option
  4. Then you can set the shortcut and see if it worked.

Notice that the action will failed if it's not granted access.

@elit8888
Copy link
Author

elit8888 commented Aug 11, 2023

@atharvstandale This script is outdated.
But you may check the answer in Stack Exchange in my reference link, seems there were scripts for different macOS versions.

@jeffhaskin
Copy link

A lot has changed in MacOS, I just figured this whole thing out for MacOS 14. Instructions here:
https://www.reddit.com/r/shortcuts/comments/163drpm/comment/koi9xhx/?utm_source=share&utm_medium=web2x&context=3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment