r/applescript • u/kenzor • Feb 27 '24
Help Request - Start / Stop Display Mirroring
I would like a pair of scripts to start and stop display mirroring (and ultimately set resolutions as well).
I have written the scripts, using Automator 'Record' tool as a basis. The scripts almost work, except no matter what I can do, I cannot get the 'Click monitor step to work, the 'click' instruction does nothing.
The script steps are:
- Launch system preferences and show 'Displays'
- Click on the monitor button
- Select 'Stop Mirroring' from the select menu
The script is below, the line beneath '-- Click monitor' appears to have no effect.
Also, when I try and iterate the list of 'monitor' buttons, I cannot programatically get their button label, does anyone know how to do that?
Thanks.
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"
-- Click monitor
click UI element 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1
-- Select drop-down menu
click pop up button 1 of group 1 of scroll area 2 of group 1 of group 2 of splitter group 1 of group 1
-- Select "Stop Mirrororing"
click menu item "Stop Mirroring" of menu 1 of pop up button 1 of group 1 of scroll area 2 of group 1 of group 2 of splitter group 1 of group 1
end tell
end tell
end tell
quit application "System Settings"
View all comments
Show parent comment
1
u/kenzor Oct 16 '24
You need to install displayplacer, set your display settings as you want them and then run
displayplacer list. Copy the final command it shows you. Then the final script is something like: