0

I recently updated my mac to Monterey and my old applescript is not working anymore and I get this error: 'System Events got an error: Can’t get pop up button 1 of window 1 of process "System Preferences". Invalid index.'

I honestly have no idea which part should I change. Thank you in advance.

tell application "System Preferences"
    set current pane to pane "com.apple.preference.displays"
    activate
end tell

tell application "System Events"
    tell process "System Preferences"
        
        click pop up button 1 of window 1
        click menu item 1 of menu 1 of pop up button 1 of window 1
    end tell
end tell

tell application "System Preferences"
    delay 10
    quit
end tell

enter image description here

1
  • Well, as an immediate step you might move your cursor to the not-recognized pop-up-button and press Shift-Cmd-4 to get its coordinates (note 'em down); next open a new script window and type: __ > tell application "System Events" to click at {[input coordinates here]}< which will display a button description in the "result" section (your button must be visible when you run the script – AND: you will NOT need the whole "string" but just the button's relevant information.) Nov 1, 2021 at 15:53

1 Answer 1

0
tell application "System Preferences"
    reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays"
    activate
end tell

tell application "System Events"
    tell application process "System Preferences"
        click pop up button "Add Display" of window "Displays"
        click menu item 2 of menu 1 of pop up button "Add Display" of window "Displays"
    end tell
end tell

tell application "System Preferences"
    delay 5
    quit
end tell
3
  • After a lot of experiments it works for me well like this
    – vit
    Nov 13, 2021 at 14:50
  • 1
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Nov 13, 2021 at 20:09
  • 1
    Welcome to Stack Overflow, and thank you for contributing an answer. Would you kindly edit your answer to to include an explanation of your code? That will help future readers better understand what is going on, and especially those members of the community who are new to the language and struggling to understand the concepts. Nov 13, 2021 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.