Tuesday, January 21, 2020

#1 2020-01-09 02:59:47 am

gannibbb
Member
Registered: 2020-01-08
Posts: 3

Enabling / Disabling Mouse keys in Catalina using Applescript

Hi, I'm quite new to Applescript (and coding in general). I'm trying to compile a code that would enable and/or disable Mouse keys in Catalina system.

I've tried following some codes which I found here, like the one copied below, but I'm getting an error saying "System Events got an error: Can’t get checkbox "Enable Mouse Keys" of window "Accessibility" of process "System Preferences"."

tell application "System Preferences"
   reveal anchor "Mouse" of pane id "com.apple.preference.universalaccess"
   activate
   delay 0.1
   tell application "System Events"
       tell process "System Preferences"
           set mouseKeysOn to the value of checkbox "Enable Mouse Keys" of window "Accessibility"
       end tell
   end tell
   quit
end tell

Is it possible to modify this code to enable mouse keys on Catalina?

Thanks for your help

Offline

 

#2 2020-01-09 04:09:19 am

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

Re: Enabling / Disabling Mouse keys in Catalina using Applescript

With the Log History window open may you try to run this modified version :

Applescript:

tell application "System Preferences"
   -- name of anchors of pane id "com.apple.preference.universalaccess" --> {"Siri", "Keyboard", "Dwell", "Captioning", "Seeing_VoiceOver", "SpeakableItems", "TextToSpeech", "Hearing", "Switch", "General", "Media_Descriptions", "Mouse", "Seeing_Display", "Virtual_Keyboard", "Seeing_Zoom"}
   
   reveal anchor "Mouse" of pane id "com.apple.preference.universalaccess"
   activate
   delay 0.1
   tell application "System Events"
       tell process "System Preferences"
           set frontmost to true
           -- name of windows --> {"Accessibilité"}
           tell window 1
               class of UI elements --> {button, button, button, checkbox, static text, button, static text, slider, static text, static text, static text, static text, checkbox, slider, checkbox, scroll area, button, button, button, toolbar}
               title of checkboxes --> {"Activer les touches de souris", "Délai de l’ouverture automatique :", "Afficher l’état d’Accessibilité dans la barre des menus"}
           end tell
           if (value of checkbox 1 of window 1) = 0 then click checkbox 1 of window 1 --"Accessibility"
       end tell
   end tell
   quit
end tell

and return the contents of the history.

As is, it's supposed to "Enable Mouse Keys" if they aren't.
If it works I would edit it so that it behaves as a switcher.
Here under High Sierra I got :

Applescript:


Don't click upon [Open this Scriplet in your Editor:] here is just a log history

tell application "System Preferences"
   get name of every anchor of pane id "com.apple.preference.universalaccess"
       --> {"Siri", "Keyboard", "Dwell", "Captioning", "Seeing_VoiceOver", "SpeakableItems", "TextToSpeech", "Hearing", "Switch", "General", "Media_Descriptions", "Mouse", "Seeing_Display", "Virtual_Keyboard", "Seeing_Zoom"}
   reveal anchor "Mouse" of pane id "com.apple.preference.universalaccess"
       --> anchor "Mouse" of pane id "com.apple.preference.universalaccess"
   activate
end tell
tell application "System Events"
   set frontmost of process "System Preferences" to true
   get name of every window of process "System Preferences"
       --> {"Accessibilité"}
   get class of every UI element of window 1 of process "System Preferences"
       --> {button, button, button, checkbox, static text, button, static text, slider, static text, static text, static text, static text, checkbox, slider, checkbox, scroll area, button, button, button, toolbar}
   get title of every checkbox of window 1 of process "System Preferences"
       --> {"Activer les touches de souris", "Délai de l’ouverture automatique :", "Afficher l’état d’Accessibilité dans la barre des menus"}
   get value of checkbox 1 of window 1 of process "System Preferences"
       --> 0
   click checkbox 1 of window 1 of process "System Preferences"
       --> checkbox "Activer les touches de souris" of window "Accessibilité" of application process "System Preferences"
end tell
tell application "System Preferences"
   quit
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 9 janvier 2020  11:05:14

Offline

 

#3 2020-01-10 03:17:27 am

gannibbb
Member
Registered: 2020-01-08
Posts: 3

Re: Enabling / Disabling Mouse keys in Catalina using Applescript

Hi, thanks for your suggestion. However, this won't work on Catalina, since the option to enable mouse keys is located within another tab named "Alternative Control Methods".

So it goes like this: System preferences / Accessibility / Pointer Control / Choose tab "Alternative Control Methods" / Enable Mouse Keys


Any ideas how to access this tab with AS?

Thanks

Offline

 

#4 2020-01-10 05:27:10 am

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

Re: Enabling / Disabling Mouse keys in Catalina using Applescript

Try with :

Applescript:

tell application "System Preferences"
   name of anchors of pane id "com.apple.preference.universalaccess" --> {"Siri", "Keyboard", "Dwell", "Captioning", "Seeing_VoiceOver", "SpeakableItems", "TextToSpeech", "Hearing", "Switch", "General", "Media_Descriptions", "Mouse", "Seeing_Display", "Virtual_Keyboard", "Seeing_Zoom"} with High Sierra
   --> {"Siri", "Seeing_ColorFilters", "Keyboard", "Dwell", "Captioning", "Seeing_VoiceOver", "TextToSpeech", "Hearing", "Dictation", "Alternate_Mouse_Buttons", "General", "Seeing_Cursor", "Media_Descriptions", "Mouse", "Seeing_Display", "Switch", "Seeing_Zoom", "Virtual_Keyboard", "Accessibility_Shortcut"} with Catalina
   
   reveal anchor "Mouse" of pane id "com.apple.preference.universalaccess"
   activate
   delay 0.1
   tell application "System Events"
       tell process "System Preferences"
           set frontmost to true
           -- name of windows --> {"Accessibilité"}
           tell window 1
               set theClasses to class of UI elements --> {button, button, button, checkbox, static text, button, static text, slider, static text, static text, static text, static text, checkbox, slider, checkbox, scroll area, button, button, button, toolbar} with High Sierra
               --> {button, checkbox, scroll area, group, toolbar, button, button, button} with Catalina
               if theClasses contains static text then
                   -- Here with "High Sierra"
                   title of checkboxes --> {"Activer les touches de souris", "Délai de l’ouverture automatique :", "Afficher l’état d’Accessibilité dans la barre des menus"}
                   if (value of checkbox 1) = 0 then click checkbox 1 --> "Activer les touches de souris"
               else
                   -- here with "Catalina"
                   -- class of UI elements of toolbar 1 --> {group, group, group, group}
                   -- class of UI elements of scroll area 1 --> {table, scroll bar}
                   -- class of UI elements of group 1 --> {tab}
                   -- class of UI elements of UI element 1 of group 1 --> {radio button, radio button, static text, slider, static text, static text, static text, static text, checkbox, slider, checkbox, static text, button, button}
                   -- name of radio buttons of UI element 1 of group 1 --> {"Souris et trackpad", "Autres méthodes de contrôle"}
                   -- name of radio button 2 of UI element 1 of group 1 --> "Autres méthodes de contrôle"
                   click radio button 2 of UI element 1 of group 1 --> "Autres méthodes de contrôle"
                   -- class of UI elements of UI element 1 of group 1--> {radio button, radio button, checkbox, button, static text, checkbox, static text, button}
                   -- title of checkboxes of UI element 1 of group 1--> {"Activer les touches de souris", "Activer les actions alternatives du pointeur"}
                   tell UI element 1 of group 1
                       if (value of checkbox 1) = 0 then click checkbox 1 --> "Activer les touches de souris"
                   end tell
               end if
           end tell
       end tell -- process
   end tell -- System Events
   quit
end tell

It's supposed to work with High Sierra and Catalina. No idea of what it does with Mojave.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 10 janvier 2020  12:26:37

Last edited by Yvan Koenig (2020-01-10 05:37:55 am)

Offline

 

#5 2020-01-10 12:35:08 pm

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

Re: Enabling / Disabling Mouse keys in Catalina using Applescript

Here is the same script triggering the UI elements by their names.

Applescript:

set theBundle to ((path to library folder from system domain as text) & "PreferencePanes:UniversalAccessPref.prefPane:") as «class furl»
if (system attribute "sys2") < 15 then
   set theKey to "202.title"
   set enableMouseKeys_loc to localized string theKey from table "MouseAndTrackpad" in bundle theBundle
   --> "Activer les touches de souris"
   if enableMouseKeys_loc is theKey then set enableMouseKeys_loc to "Enable Mouse Keys" -- useful before Mojave
else
   set theKey to "DUk-XY-hWn.title"
   set enableMouseKeys_loc to localized string theKey from table "PointerControl" in bundle theBundle
   --> "Activer les touches de souris"
   set theKey to "QU4-I1-WiG.label"
   set alternativeControlMethods_loc to localized string theKey from table "PointerControl" in bundle theBundle
   --> Autres méthodes de contrôle
end if
set theKey to "NSPrefPaneIconLabel"
set accessibility_loc to localized string theKey from table "InfoPlist" in bundle theBundle

tell application "System Preferences"
   name of anchors of pane id "com.apple.preference.universalaccess" --> {"Siri", "Keyboard", "Dwell", "Captioning", "Seeing_VoiceOver", "SpeakableItems", "TextToSpeech", "Hearing", "Switch", "General", "Media_Descriptions", "Mouse", "Seeing_Display", "Virtual_Keyboard", "Seeing_Zoom"} with High Sierra
   --> {"Siri", "Seeing_ColorFilters", "Keyboard", "Dwell", "Captioning", "Seeing_VoiceOver", "TextToSpeech", "Hearing", "Dictation", "Alternate_Mouse_Buttons", "General", "Seeing_Cursor", "Media_Descriptions", "Mouse", "Seeing_Display", "Switch", "Seeing_Zoom", "Virtual_Keyboard", "Accessibility_Shortcut"} with Catalina
   reveal anchor "Mouse" of pane id "com.apple.preference.universalaccess"
   activate
   delay 0.1
   tell application "System Events" to tell process "System Preferences"
       set frontmost to true
       -- name of windows --> {"Accessibilité"}
       tell window accessibility_loc
           set theClasses to class of UI elements --> {button, button, button, checkbox, static text, button, static text, slider, static text, static text, static text, static text, checkbox, slider, checkbox, scroll area, button, button, button, toolbar} with High Sierra
           --> {button, checkbox, scroll area, group, toolbar, button, button, button} with Catalina
           if theClasses contains static text then
               -- Here with "High Sierra"
               -- title of checkboxes --> {"Activer les touches de souris", "Délai de l’ouverture automatique :", "Afficher l’état d’Accessibilité dans la barre des menus"}
               if (value of checkbox enableMouseKeys_loc) = 0 then click checkbox enableMouseKeys_loc --> "Activer les touches de souris"
           else
               -- here with "Catalina"
               -- class of UI elements of toolbar 1 --> {group, group, group, group}
               -- class of UI elements of scroll area 1 --> {table, scroll bar}
               -- class of UI elements of group 1 --> {tab} -- what is listed as ‘tab‘ is in fact a ‘tab group’
               tell tab group 1 of group 1 -- here we are in the tab group "Souris et trackpad"
                   -- class of UI elements --> {radio button, radio button, static text, slider, static text, static text, static text, static text, checkbox, slider, checkbox, static text, button, button}
                   -- name of radio buttons --> {"Souris et trackpad", "Autres méthodes de contrôle"}
                   click radio button alternativeControlMethods_loc --> "Autres méthodes de contrôle"
               end tell
               tell tab group 1 of group 1 -- now we are in the tab group "Autres méthodes de contrôle"
                   -- class of UI elements --> {radio button, radio button, checkbox, button, static text, checkbox, static text, button}
                   --title of checkboxes --> {"Activer les touches de souris", "Activer les actions alternatives du pointeur"}
                   if (value of checkbox enableMouseKeys_loc) = 0 then click checkbox enableMouseKeys_loc --> "Activer les touches de souris"
               end tell
           end if
       end tell -- window 1
   end tell -- process …
   quit
end tell -- "System Preferences"

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 10 janvier 2020  19:35:03

Offline

 

#6 2020-01-17 07:11:38 am

gannibbb
Member
Registered: 2020-01-08
Posts: 3

Re: Enabling / Disabling Mouse keys in Catalina using Applescript

Worked great, thanks so much for your help!

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)