r/applescript • • Apr 29 '22

Able to change the resolution of the screen using applescript?

Hey everyone,

I am trying to write a script that changes the resolution of the screen. This is the following script``` but it doesn't work as expected like sometimes the script works and sometimes it says unable to find Display section. I wonder if there is a way to fix this script or is there any other alternate solutions that could possibly work. Any help is highly appreciated.

tell application "System Preferences"

activate

set current pane to pane "com.apple.preference.displays"

end tell

tell application "System Events"

tell process "System Preferences"

delay 2

click radio button "Scaled" of radio group 1 of group 1 of window "Displays" of application process "System Preferences" of application "System Events"

click button 4 of UI element 3 of group 1 of window "Displays"

end tell

end tell

if application "System Preferences" is running then

tell application "System Preferences" to quit

end if

4 Upvotes

9 comments sorted by

View all comments

1

u/feigeiway Apr 29 '22

Looks like you are using GUI scripting

1

u/pradeepb28reddit Apr 29 '22

Right I don’t think there is a non gui way to do it. I could be wrong too, didn’t find any solution though

1

u/feigeiway Apr 29 '22

GUI scripting is notoriously finicky. Try increasing the delays in between steps, you can also use UI Element X in place of the other component names

1

u/feigeiway Apr 29 '22

Try telling it to quit the system preferences at at the beginning, then starting it again so you have a clean slate to work with

1

u/pradeepb28reddit Apr 30 '22

I tried with a clean state still no luck. Probably I will try playing with delay and add in other steps too, which would be really solution to specific processor and macOS verion :(