Automation to change display resolution for screen sharing

Hi All,
I spent some time today trying to find a solution for this and didn’t quite find one that fit my needs so ended up cobbling together something from older posts. Figured I’d share if anyone is looking to do similar things and to see if anyone has input for improvements.

Problem Definition

I often need to screenshare on calls and many members of the call will be on laptop screens with a lower resolution than my external display. My non-automated workflow was to tell everyone to give me a min prior to sharing and go into system preferences to change the resolution. This has gotten tiring and felt like a prime candidate for automation.

Solution

I wasn’t able to find a Shortcut that did this but found a SO post about using apple script. This was my starting point.
Below is my final script. I also wanted to be able to trigger this from raycast or from a keyboard shortcut so that is what the additional Raycast meta in comments are about.
Currently this is working on macOS Monterey 12.6 and hasn’t been tested on any other versions.

#!/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
			set elems to entire contents of UI element 6 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"

As mentioned above, I’m happy to take feedback on this. I haven’t done hardly any applescripting so I’m sure there are better ways of doing things.

1 Like

I use a free app called Display Menu, but I I unlocked it (£1.49 accordng to the App Store) to get a few extra features including AppleScript support. This gave me an option I found a little more reliable to work with than triggering clicks as per the standalone AppleScript as you have used above.

I started with some AppleScript somewhat similar to what you have, but I got occasional mis-timings, so ended up searching out an alternative. Your mileage may vary, but for me, it was a either prone to mis-timing or a bit too slow to run (additional purposeful delays).

As you might expect, using a display management app with dedicated AppleScript support, I ended up with a much simpler AppleScript call.

tell application "Display Menu"
	select resolution "1920 x 1080 60.0 Hz non-Retina" on display "VZ27A"
end tell

I have this as one of the actions in the Keyboard Maestro macro I use to set up my Mac for screen recording - which I trigger via Alfred.

Very cool. Thanks @sylumer!

Thanks for this.

I’ve been using scres.swift but it’s quite slow for my 6yo machine. This changes the resolution instantly.