-
-
Save AkdM/dcad6ef973c1d4574af803a9a214c6f5 to your computer and use it in GitHub Desktop.
-- Kill System Preferences first if already open | |
if application "System Preferences" is running then | |
tell application "System Events" | |
set theID to unix id of processes whose name is "System Preferences" | |
try | |
do shell script "kill -9 " & theID | |
delay 0.1 | |
end try | |
end tell | |
end if | |
try | |
tell application "System Preferences" | |
activate | |
set the current pane to pane id "com.apple.preferences.AppleIDPrefPane" | |
tell application "System Events" | |
repeat until window "Apple ID" of application process "System Preferences" exists | |
end repeat | |
set theWindow to window "Apple ID" of application process "System Preferences" | |
-- Select iCloud | |
repeat until row 6 of table 1 of scroll area 1 of theWindow exists | |
end repeat | |
select row 6 of table 1 of scroll area 1 of theWindow | |
-- Right part of the window | |
set rowDetails to group 1 of theWindow | |
repeat until row 4 of table 1 of scroll area 1 of rowDetails | |
end repeat | |
-- Select the "Hide my Email" row | |
set hideMyEmailRow to row 4 of table 1 of scroll area 1 of rowDetails | |
repeat until button of UI element 1 of hideMyEmailRow exists | |
end repeat | |
click button of UI element 1 of hideMyEmailRow | |
log "Clicked at: " & (value of static text 1 of UI element 1 of hideMyEmailRow) | |
-- New opened window, which is a sheet | |
set hideMyEmailSheet to sheet 1 of theWindow | |
-- Wait for the busy indicator to appear | |
repeat until busy indicator 1 of hideMyEmailSheet exists | |
end repeat | |
-- Then wait for it to disappear | |
repeat until (not (busy indicator 1 of hideMyEmailSheet exists)) | |
end repeat | |
set sheet1 to sheet 1 of theWindow | |
set addButton to button 1 of group 3 of group 1 of group 1 of UI element 1 of scroll area 1 of sheet1 | |
click addButton | |
end tell | |
log "End" | |
end tell | |
on error errMsg | |
log "ERR: " & errMsg | |
end try |
Seems to not work on macOS Monterey 12.6, failing on line 54:
Clicked at: Hide My Email ERR: System Events got an error: Can’t get group 1 of UI element 1 of sheet 1 of window "Apple ID" of application process "System Preferences". Invalid index.
Is there an Xcode tool I can use to find the group / sheet / button numbers for a window?
If it's helpful, this is the window as it appears to me:
On my Mac (Monterey 12.6) the first group instance requires amending from "3" to "1"
Replace line 54...
set addButton to button 1 of group 3 of group 1 of group 1 of UI element 1 of scroll area 1 of sheet1
with the following line...
set addButton to button 1 of group 1 of group 1 of group 1 of UI element 1 of scroll area 1 of sheet1
@DeepHeat01 that did it, thanks!
Oops, I didn't see those notifications. Sorry!
I will maybe try to make something more like an app, since AppleScript isn't very practical for this usage. But Apple is limiting almost everything on this side unfortunately 👎
Seems to not work on macOS Monterey 12.6, failing on line 54:
Is there an Xcode tool I can use to find the group / sheet / button numbers for a window?
If it's helpful, this is the window as it appears to me: