Tuesday, June 2, 2020

#1 2020-04-07 12:54:53 am

Rougher
Member
Registered: 2020-03-30
Posts: 4

Focus on Apple ID text box

Hi all,

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

Applescript:

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:

error "System Events got an error: Can’t get group 1 of group 1 of window 1 of process \"System Preferences\". Invalid index." number -1719 from group 1 of group 1 of window 1 of process "System Preferences"



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

Last edited by Nigel Garvey (2020-04-07 04:56:16 am)

Offline

 

#2 2020-04-07 02:14:47 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4389

Re: Focus on Apple ID text box

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"

Applescript:

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

Offline

 

#3 2020-04-07 08:26:48 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 1259

Re: Focus on Apple ID text box

Applescript:


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

Last edited by KniazidisR (2020-04-07 09:35:23 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#4 2020-04-07 10:10:04 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4389

Re: Focus on Apple ID text box

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

Last edited by Yvan Koenig (2020-04-07 10:13:19 am)

Offline

 

#5 2020-04-07 11:07:14 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4389

Re: Focus on Apple ID text box

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

Offline

 

#6 2020-04-07 11:56:26 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4389

Re: Focus on Apple ID text box

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

Applescript:

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

Offline

 

#7 2020-04-08 03:48:20 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4389

Re: Focus on Apple ID text box

An alternate protocol is to trigger directly the AppleID prefpane.

This code is supposed to do the job.

Applescript:

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

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)