I would like to have an AppleScript that toggles between "Default for display" in System Preferences and "Scaled" "Larger Text".
The script should detect the current state of the display and toggle to the other state (i.e., if in Default for display, switch to scaled larger text).
I gut this far with my script (that I got from this site and this stackexchange page), but it seems that I can't get to virtually "click" left most icon out of the five available ones:
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.displays"
reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays"
end tell
local indexToUse
-- Now lets make the necessary changes
tell application "System Events"
tell tab group 1 of window "LG UltraFine" of application process "System Preferences" of application "System Events"
tell radio group 1
if (value of radio button "Scaled") = 0 then
-- Click the "Scaled" radio button
click radio button "Scaled"
tell radio group 2
click radio button 1 of radio group 2
end tell
else
click radio button "Default for display"
end if
end tell
end tell
end tell
-- Quit "System Preferences"
quit application "System Preferences"
When running the script, if System Preferences are in "Default for display", I get the following Script Error: System Events got an error: Can’t get radio group 2 of radio group 1 of tab group 1 of window "LG UltraFine" of application process "System Preferences". Invalid index.
I would like to be able to click on the button circled in red in the attached screenshot.
tell application "System Events" to get every UI element of window 1 of application process "System Preferences"
and then e.g.tell application "System Events" to get properties of radio button 1 of window 1 of application process "System Preferences"
whereradio button 1
can be that orradio button "Left"
and other designators, e.g.radio button 2
orradio button "Bottom"
, etc.