UPDATE: I think I found a way, changing the script from another user that used it for the Shortcuts tab. Here’s the code and please let me know if there’s a better way to write it, that takes less time and all that:
tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.keyboard"
tell application "System Events"
click radio button "Text" of tab group 1 of window "Keyboard" of application process "System Preferences"
end tell
end tell
If this is good, can I add this to the contextual menu?
Initial post
I’m trying to find a way to create a keyboard shortcut using Better Touch Tool to open the “System Preferences > Keyboard > Text” tab, because I see myself adding new words there and I want to make the process easier and faster.
Can someone provide me with the script, please?
Also, is there a way to add options to the contextual menu (for example when I highlight a word and right click) that would automatically read that script?
Similar to the “Learn Spelling”, but in this case it would run the script and open the Text tab.
I can see you helped another Mac user. Would you be able to advise, what Apple Script on macOS Sonoma would open: System Settings >> Keyboard >> Keyboard Shortcuts… >> App Shortcuts?
The script below works on my Ventura and Sonoma machines, although sometimes it looks as if nothing’s happening and I have to wait several seconds for the final result to be achieved.
I’ve found it necessary to use GUI Scripting as well. System Settings’s “Keyboard” pane has anchors called “CapsLockInputSources”, “CustomizeModifierKeys”, “Dictation”, “FunctionKeys”, “InputSources”, “Keyboard”, “LanguageInputMethods”, “ModifierKeys”, “Shortcuts”, “Spelling”, “TextReplacements”, “TouchBarSettings”, and “UseSmartQuotes”. Reveal-ing some of them by script opens the “Keyboard Shortcuts…” list, and at least three of them open it with “Modifier Keys” selected. So it’s then necessary to use GUI Scripting to select the row containing “App Shortcuts”. I’ve not been able to find this text in the scriptable UI elements, so it has to be done by row number. Although it’s the same version of System Settings on both systems, and the list looks exactly the same in both cases, the relevant row’s numbered 10 on my Ventura machine and 11 on the Sonoma! I hope this works for you too….
set OS to (system info)'s system version
if (OS begins with "13") then
set r to 10
else if (OS begins with "14") then
set r to 11
else
error "I don't know what to do in this macOS version!"
end if
tell application "System Settings"
activate
reveal anchor "Shortcuts" of ¬
pane id "com.apple.Keyboard-Settings.extension"
end tell
tell application "System Events"
tell application process "System Settings"
set frontmost to true
tell sheet 1 of window 1
repeat until (it exists)
delay 0.2
end repeat
set selected of row r of outline 1 of scroll area 1 of group 1 of splitter group 1 of group 1 to true
end tell
end tell
end tell
I am getting a lot of pop-up windows and eventually it ends up with an error.
Text of the pop-ups:
“Calendar.app” would like to
access files in your Desktop
folder.
“Calendar.app” would like to
access files in your Documents
folder.
“Calendar.app” wants
access to control “System
Events.app”. Allowing control will
provide access to documents
and data in “System Events.app”,
and to perform actions within
that app. Calendar uses AppleEvents to
communicate with other applications to
extend Office functionality.
The action “Run AppleScript”
encountered an error: “System
Events got an error: Automator
Workflow Runner
(WorkflowServiceRunner, App
Shortcuts) is not allowed
assistive access.”
I understand, that the app in the pop-up depends on the app opened (active) at that moment, when I triggered the quick action. I click on Allow and it does not help at first, but when I try the quick action again, then it works.
Is there a way to avoid approving access to all apps manually?
This is a great adventure :-). I love automating things! Thank for your help!
Once the application running the script (ie. one of the script editors, the Script Menu, the script itself if saved as an application, or what appears to be Automator in your case) is given the necessary permissions to control System Events and the GUI, that should be enough for that application. It shouldn’t need to ask again, even with a different script. I don’t understand how Calendar, Shortcuts, and Photos are being dragged into it. They’re not mentioned in the script.