Focus on Apple ID text box

Hi all,

I need to focus on Apple ID text box. I tried this script:

on run
	try
		if application "System Preferences" is running then do shell script "killall 'System Preferences'"
	end try
	repeat until application "System Preferences" is not running
		delay 0.1
	end repeat
	tell application "System Preferences"
		launch
		activate
	end tell
	
	tell application "System Events"
		tell process "System Preferences"
			set frontmost to true
			delay 1
			tell window 1
				click button "Sign In"
			end tell
		end tell
	end tell
	
	tell application "System Events"
		tell process "System Preferences"
			set frontmost to true
			delay 1
			tell window 1
				tell group 1 of group 1
					delay 1
					set focused of text field 1 to true
				end tell
			end tell
		end tell
	end tell
end run

([/AppleScript] tag lower-cased by NG.)

But I get this error:

Can somebody help me to understand what is the problem here?
Thank you.

Which pane are you wanting to trigger ?
Here, when I run a subset of your code I don’t find a button whose name resemble to “Sign in”

on run
	try
		if application "System Preferences" is running then do shell script "killall 'System Preferences'"
	end try
	repeat until application "System Preferences" is not running
		delay 0.1
	end repeat
	tell application "System Preferences"
		launch
		activate
	end tell
	
	tell application "System Events"
		tell process "System Preferences"
			set frontmost to true
			delay 1
			tell window 1
				get class of UI elements --> {scroll area, button, button, button, toolbar}
				(get subrole of buttons) --> {"AXCloseButton", "AXZoomButton", "AXMinimizeButton"}
				--click button "Sign In"
				tell scroll area 1
					class of UI elements --> {button, button, button, button, button, button, button, button, button, button, button, button, button, button, button, button, button, button, button, button, button, button, button, button, button, button, button, button, button, button, button, button}
					name of buttons
					(* 
					{"Général", "Bureau et écono-
miseur d’écran", "Dock", "Mission
Control", "Langue et
région", "Sécurité et
confidentialité", "Spotlight", "Notifications", "CD et DVD", "Moniteurs", "Économiseur
d’énergie", "Clavier", "Souris", "Trackpad", "Imprimantes
et scanners", "Son", "Disque de
démarrage", "iCloud", "Comptes
Internet", "App Store", "Réseau", "Bluetooth", "Extensions", "Partage", "Utilisateurs et
groupes", "Contrôle
parental", "Siri", "Date et heure", "Time
Machine", "Accessibilité", "Flash Player", "Java"}
*)
				end tell -- scroll area
				tell toolbar 1
					class of UI elements --> {group, group, group, group}
					
					tell group 1
						class of UI elements --> {group}
						tell group 1
							class of UI elements --> {button, button}
							description of buttons --> { "Précédent", "Suivant"}
						end tell
					end tell
					tell group 2
						class of UI elements --> {group}
						tell group 1
							class of UI elements --> {button}
							name of button 1 --> "Tout afficher"
						end tell
					end tell
					tell group 3
						class of UI elements --> {static text}
						value of static text 1 --> "Préférences Système"
					end tell
					tell group 4
						class of UI elements --> {text field}
						subrole of text field 1 --> "AXSearchField"
					end tell
				end tell
			end tell
		end tell
	end tell
end run

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 7 avril 2020 10:14:39


on run
	
	tell application "System Preferences"
		if running then
			quit
			repeat while running
				delay 0.1
			end repeat
		end if
		activate
	end tell
	
	tell application "System Events" to tell process "System Preferences"
		repeat until window "System Preferences" exists -- doesn't appear quickly
			delay 0.1
		end repeat
		-- when you are Signed Out, button "Sign In" doesn't appear quickly
		-- when you are Signed In, button "Sign In" doesn't appear at all
		tell window "System Preferences"
			repeat until ((button "Apple ID" exists) or (button "Sign In" exists))
				delay 0.1
			end repeat
			if button "Sign In" exists then click button "Sign In"
		end tell
	end tell
	
end run

May you check if I am right ?

It seems that these buttons belong to a prefpane named “AppleIDPrefPane.prefPane” which is unavailable in High Sierra and Mojave.

I have no idea about which prefpane was supposed to do the same job in these ‘old’ systems.

A screenshot displaying the contents of this pane would be welcome.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 7 avril 2020 18:09:57

I was right.
This new prefpane offer features which, under 10.13.6 are in a pane named iCloud.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 7 avril 2020 19:07:04

May you try this version supposed to be able to work with every language setting.

on run
	
	if (system attribute "sys2") < 15 then error "This script requires at least macOS 10.15"
	
	set theBundle to path to application "System Preferences"
	set SystemPreferences_loc to localized string "CFBundleName" from table "InfoPlist" in bundle theBundle --> "Préférences Système"
	
	set theBundle to ((path to library folder from system domain as text) & "PrivateFrameworks:AccountsUI.framework:") as «class furl»
	set signIN_loc to localized string "SIGN_IN" in bundle theBundle --> "Ouvrir une session"
	
	set theBundle to ((path to library folder from system domain as text) & "PreferencePanes:AppleIDPrefPane.prefPane:") as «class furl»
	set appleID_loc to localized string "CFBundleName" from table "InfoPlist" in bundle theBundle
	
	tell application "System Preferences"
		if running then
			quit
			repeat while running
				delay 0.1
			end repeat
		end if
		activate
	end tell
	
	tell application "System Events" to tell process "System Preferences"
		repeat until window SystemPreferences_loc exists -- doesn't appear quickly
			delay 0.1
		end repeat
		-- when you are Signed Out, button "Sign In" doesn't appear quickly
		-- when you are Signed In, button "Sign In" doesn't appear at all
		tell window SystemPreferences_loc
			repeat until ((button appleID_loc exists) or (button signIN_loc exists))
				delay 0.1
			end repeat
			if button signIN_loc exists then click button signIN_loc
		end tell
	end tell
	
end run

On systems running in English I’m quite sure that it works.
I have a doubt for the string signIN_loc in other languages (French for instance) because the system use two different strings spelled “Sign In” in English.
One is “Se Connecter”, another one is “Ouvrir une session”.
Here I choose the version “Ouvrir une session”.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 7 avril 2020 19:55:56

An alternate protocol is to trigger directly the AppleID prefpane.

This code is supposed to do the job.

try
	tell application "System Preferences"
		activate
		reveal pane id "com.apple.preferences.AppleIDPrefPane"
	end tell
on error errmsg
	error "The preference pane AppleIDPrefPane is available only in Catalina or higher"
end try
(*
set theBundle to path to application "System Preferences"
set SystemPreferences_loc to localized string "CFBundleName" from table "InfoPlist" in bundle theBundle --> "Préférences Système"
*)
set theBundle to ((path to library folder from system domain as text) & "PrivateFrameworks:AccountsUI.framework:") as «class furl»
set signIN_loc to localized string "SIGN_IN" in bundle theBundle --> "Ouvrir une session"

set theBundle to ((path to library folder from system domain as text) & "PreferencePanes:AppleIDPrefPane.prefPane:") as «class furl»
set appleID_loc to localized string "CFBundleName" from table "InfoPlist" in bundle theBundle

tell application "System Events" to tell process "System Preferences"
	set frontmost to true
	repeat until window appleID_loc exists
		delay 0.1
	end repeat
	
	tell window appleID_loc
		properties of buttons
		if exists button signIN_loc then click button signIN_loc
	end tell
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 8 avril 2020 11:48:06