do shell script "open x-apple.systempreferences:com.apple.Displays-Settingspreference.extension"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 "Displays")
delay 0.1
end repeat
tell window "Displays"
set displayOptions to UI element 1 of group 1 of scroll area 2 of group 1 of group 2 of splitter group 1 of group 1
set theButton to (first button of displayOptions whose value of attribute "AXAttributedDescription" contains "Selected")
if help of theButton is "2560 × 1440" then
click button 1 of displayOptions
else
click button 3 of displayOptions
end if
end tell
end tell
end tell
quit application "System Settings"
Fix for wch1zpink's answer on macOS 1012.150.41:
tell application "System Preferences"
reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
end tell
tell application "System Events"
to tell application process "System Preferences" to tell
window "Built-in Retina Display"
set isScaled torepeat valueuntil of(exists radio button "Scaled" of tabradio group 1
of ifgroup isScaled1 =of 0window then"Displays")
click radio button "Scaled" of tab groupdelay 0.1
clickend radiorepeat
button 1 of radio group 1 of grouptell 1window of"Displays"
tab group 1
else
set isScaled to value clickof radio button "Default for display""Scaled" of tabradio group 1
end if
end tell
quit applicationof "Systemgroup Preferences"1
Fix for wch1zpink's answer on macOS 12.0.1:
tell application "System Preferences"
reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
endif tell
tellisScaled application= "System0 Events"then
tell application process "System Preferences"
repeat until (existsclick radio button "Scaled" of radio group 1 of group 1
of window "Displays")
delay 0.1
click button 1 of UI element 3 of endgroup repeat1
tell window "Displays" else
set isScaled to value ofclick radio button "Scaled""Default for display" of radio group 1 of group 1
end if
isScaled = 0 then
end tell
end tell
end tell
quit application "System Preferences"
Fix on macOS 10.15.4:
tell application click"System radioPreferences"
button "Scaled" of radioreveal groupanchor 1"displaysDisplayTab" of grouppane 1"com.apple.preference.displays"
end tell
tell application "System Events" to tell process "System Preferences" to tell window "Built-in Retina Display"
set clickisScaled buttonto 1value of UIradio elementbutton 3"Scaled" of tab group 1
if isScaled = 0 then
else
click radio button "Scaled" of tab group 1
click radio button "Default for display"1 of radio group 1 of group 1
of tab group 1
else
end if
click radio button "Default for display" endof telltab group 1
end tellif
end tell
quit application "System Preferences"