How can I enable Speakable Items via Applescript?

I want to enable Speakable Items from Applescript.

From my searches, I gather that this could be:

  • using a terminal or shell command
  • modifying a .plist file or,
  • using GUI Scripting

I haven’t found anything of the 1st 2. With GUI Scripting, I can see that Systems Preferences is scriptable, and I can get to pane id “com.apple.preference.universalaccess” and get the names of the anchors. But I can’t seem to click the button. I’ve used a range of variations on this:

tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.universalaccess"
	reveal anchor "SpeakableItems" of pane id "com.apple.preference.universalaccess"
end tell

tell application "System Events"
	tell process "System Preferences"
		tell window "Accessibility"
			click radio button 1
		end tell
	end tell
end tell

I’ve tried naming the button (“on”, “off”, “Speakable Items”), I’ve tried with and without /tab and /radio button group, but I can’t get it to click the darn button. I have uses Accessibility Inspector to try to determine the correct syntax, but there I am a bit out of my depth.

Error message is of the form:

System Events got an error: Can’t get radio button 1 of window “Accessibility” of process “System Preferences”. Invalid index.

I haven’t found a query or answer to this exact problem, either in these forums, or by Googling. Lots of info on how to launch a script from Speakable Items, nothing on the other way around.

Any help would be appreciated, plus it’s an intriguing little puzzle.

Model: MacBook Pro (2012)
AppleScript: 2.2.3
Browser: Safari 536.26.17
Operating System: Mac OS X (10.8)

(1) The icon entitled “Speakable Items” available on the left side of the pane isn’t a radio button.
It’s an Image in a Cell of a Row of a Table in a ScrollArea in a Standard Window
Triggering it activate the wanted pane in the pane.

(2) In the “Speakable Items” pane, the item to click isn’t a radio button, it’s a Checkbox i an Group in a Standard Window.

Yvan KOENIG (VALLAURIS, France) vendredi 15 mars 2013 17:33:33

I tried this, but still get the same error. Something wrong.

tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.universalaccess"
	reveal anchor "SpeakableItems" of pane id "com.apple.preference.universalaccess"
end tell
tell application "System Events"
	click radio button 1 of radio group 1 of tab group 1 of window "Accessibility" of process "System Preferences"
end tell

@Yvan:

  1. I know “Speakable Items” isn’t a button. I activated it to populate the “Accessibility” window with the buttons I want to clicl.

  2. In OS 10.8 it certainly looks like a radio button”and there is a checkbox below for “Upon Recognition – Speak Command Acknowledgement”. Are you saying I should try something like:

click checkbox 1 of tab group 1

?

Without /tab group, it clicks the checkbox “Enable for assistive devices”. WIth /tab group it can’t find a tab group.

Can’t seem to reference the items in the pane (or whatever it is) brought up by clicking “settings” in the tabs above the right side of the window.

As I’m working with a French system, I wrongly identified the targetted anchor.

You missed one hierarchy level.


tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.universalaccess"
	reveal anchor "SpeakableItems" of pane id "com.apple.preference.universalaccess"
end tell
tell application "System Events" to tell process "System Preferences" to tell window 1
	click radio button 1 of radio group 1 of tab group 1 of group 1 # you missed the level "group 1"
end tell

Yvan KOENIG (VALLAURIS, France) vendredi 15 mars 2013 21:18:01

Yvan for the win! Totally works. (Although, the first time I ran it, it left both radio buttons checked…not afterwards, though.)

More questions:

What does ‘group 1’ refer to? (What’s a group?)

Is there a way to simply toggle the radio button, or do I need to do an if/then?

Thanks!

In this instance the group is the two radio buttons, one off, one on.

Yvan had me use:

radio button 1 of radio group 1 of tab group 1 of group 1

which worked.

I see radio group 1 but also group 1–isn’t the 1st of these the group of 2 buttons? But group 1 contains tab group 1. It seems to be the right hand side of the “accessibility” window but I hadn’t run across “group” as a container before.

Wrong

Here the group is the main container embedding the different anchors.

The hierarchy is :

window

group 1

tab group 1

radio group 1

radio butoon 1 (& 2)

There is no need to test the status of the radio buttons.
If it was inactive, it will be actived and the other(s) one(s) will be automatically disactived.
If it was already active, clicking it will change nothing.

I got these info with the Apple’s Accessibility Inspector.

Yvan KOENIG (VALLAURIS, France) samedi 16 mars 2013 10:11:07

Merci Yvan.

But, as for testing the status:

I might like the script to turn Speakable Items on if it is off, or off if it is on.

Is this possible with a single command?


tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.universalaccess"
	reveal anchor "SpeakableItems" of pane id "com.apple.preference.universalaccess"
end tell
tell application "System Events" to tell process "System Preferences" to tell window 1
	tell radio group 1 of tab group 1 of group 1
		if value of radio button 1 is 1 then
			click radio button 2
		else
			click radio button 1
		end if
	end tell
end tell

or


tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.universalaccess"
	reveal anchor "SpeakableItems" of pane id "com.apple.preference.universalaccess"
end tell
tell application "System Events" to tell process "System Preferences" to tell window 1
	tell radio group 1 of tab group 1 of group 1
		click radio button (1 + (value of radio button 1))
	end tell
end tell

Yvan KOENIG (VALLAURIS, France) samedi 16 mars 2013 22:29:11

Yvan,

J’aime beaucoup l’elegance de la deuxième solution.

Merci,

Dave

Hello, any idea why neither of the above scripts do not work under Mavericks"

Hi daveonmacscript,

I think you can still script SpeechRecognitionServer. Here’s the dictionary:

gl,
kel

Here’s to get the Speech Feedback Window:

tell application "SpeakableItems" to activate

gl,
kel

Sweet! Thanks!

What if I would like to toggle activation; off if on and on if off?
Cheers!

Hi vicsandr,

Sorry I got your name wrong. I wasn’t looking at the dates. :slight_smile:

This seems to be working:

set bundle_id to "com.apple.inputmethod.AssistiveControl"
tell application "System Events"
	try
		set proc_id to id of first process whose bundle identifier is bundle_id
		set is_running to true
	on error
		set is_running to false
	end try
end tell
if is_running then
	tell application id bundle_id to quit
else
	tell application id bundle_id to launch
end if

The only problem I’ve found so far is that quitting the application doesn’t update in System Preferences when it is open.

gl,
kel

HI.

The structure of the anchor window has changed. The tab group containing the radio group is no longer in ‘group 1’:


tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.universalaccess"
	reveal anchor "SpeakableItems" of pane id "com.apple.preference.universalaccess"
end tell
tell application "System Events" to tell process "System Preferences" to tell window 1
	tell radio group 1 of tab group 1 -- of group 1
		click radio button (1 + (value of radio button 1))
	end tell
end tell

I don’t know why, but this line is not updating in System preferences even when System Preferences is not open.

 tell application id bundle_id to quit

Maybe there some other helper process that needs to quit.

Checking it out,
kel