Search code examples
macosapplescript

How to click on iCloud button in System Preferences using applescript


I am trying to get the script to click the iCloud button, but I am getting the syntax/logic incorrect.

tell application "System Preferences"
    activate
    set current pane to pane id "com.apple.preferences.internetaccounts"
    delay 1
end tell
tell application "System Events"
    tell process "System Preferences"
        click button "iCloud" of window "Internet Accounts"
    end tell
end tell

Help is much appreciated. I am on Monterey (12,4) iMac.

enter image description here


Solution

  • Try this.

    tell application "System Preferences"
        activate
        set current pane to pane id "com.apple.preferences.internetaccounts"
    end tell
    
    tell application "System Events" to tell process "System Preferences"
        repeat until exists of UI element "iCloud" of UI element 1 of row 1 of ¬
            table 1 of scroll area 1 of group 1 of window "Internet Accounts"
            delay 0.1
        end repeat
        click button "iCloud" of UI element 1 of row 1 of table 1 of scroll area 1 of ¬
            group 1 of window "Internet Accounts"
    end tell