Script to open the "System Preferences > Keyboard > Text" tab?

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"
	set current pane to pane id ""
	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? :slight_smile:

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.

Thanks! :slight_smile:

Model: MacBook Pro 13" Mid 2012
AppleScript: 2.11
Browser: Safari 605.1.15
Operating System: macOS 10.15

Hi. This would be better as it doesn’t use GUI Scripting:

tell application "System Preferences"
	reveal anchor "Text" of pane id ""
end tell

Thank you SO MUCH!

That works like a charm and it’s even cleaner and shorter than “my” code! :smiley:
Really appreciate your time and help!


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?

Many thanks :slight_smile:

Hi @Jan_Honza_Done. Welcome to MacScripter!

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…. :slightly_smiling_face:

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
	error "I don't know what to do in this macOS version!"
end if

tell application "System Settings"
	reveal anchor "Shortcuts" of ¬
		pane id ""
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
1 Like

Many thanks Nigel.

I am getting a lot of pop-up windows and eventually it ends up with an error.

Text of the pop-ups:

“” would like to
access files in your Desktop

“” would like to
access files in your Documents

“” wants
access to control “System”. Allowing control will
provide access to documents
and data in “System”,
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!

I have found the way - to use the + button to add other missing application to the list

So now I made all apps in my dock work :-). The only one left is Photos, which still gives me a message below:

The action “Run AppleScript”
encountered an error: “Not
authorised to send Apple events
to System Events.”

Here is its screenshot. Also, the System Settings is opened, but it stops at a different page - Modifier Keys

Hi @Jan_Honza_Done.

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. :face_with_raised_eyebrow: