Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Start dictation with applescript

Is there a way to start OS X new dictation from AppleScript?


I tried :



tell application "DictationIM" to activate


but it did not seem to work although it didn't give me an error.


Any clue?

MacBook Pro (15-inch Mid 2009), OS X Mountain Lion (10.8.2)

Posted on Nov 22, 2012 6:22 PM

Reply
7 replies

Nov 23, 2012 5:39 AM in response to seblavoie

Hi,


If you don't mind using GUI Scripting (you must enable access for assistive devices in the Accessibility System Preference pane), the following script should toggle the Dictation switch between On and Off.


tell application "System Preferences"

reveal pane id "com.apple.preference.speech"

-- activate -- only if you wish to make the Dictation & Speech window visible

tell application "System Events"

tell process "System Preferences"

tell window "Dictation & Speech"

tell tab group 1

clickradio button "Dictation"

tell radio group 1

if value of radio button "On" is 0 then

clickradio button "On"

else

clickradio button "Off"

end if

end tell

end tell

if sheet 1 exists then

tell sheet 1

clickbutton "Enable Dictation"

repeat while sheet 1 exists

end repeat

end tell

end if

end tell

end tell

end tell

quit-- optional

end tell


Hope it can help.


Message was edited by: Pierre L.

Oct 28, 2014 5:02 AM in response to seblavoie

I wish we didn't have to resort to GUI scripting. If there is another way you know of, please post. In the meantime, I've combined the two very helpful scripts above, and added notifications and error checking. It also auto-quits system preferences if it hadn't been open before, and adds appropriate delays to launch it. Hope this helps.


set ttoggle to "Off" set sprunning to application "System Preferences" is running try tell application "System Preferences" reveal pane id "com.apple.preference.speech" if not sprunning then repeat delay 1 tell me if application "System Preferences" is running then exit repeat end tell end repeat activate -- seems to be needed if sys pref hadn't been running reveal pane id "com.apple.preference.speech" delay 2 else activate -- only if you wish to make the Dictation & Speech window visible end if tell application "System Events" tell process "System Preferences" tell window "Dictation & Speech" tell tab group 1 click radio button "Dictation" tell radio group 1 if value of radio button "On" is 0 then click radio button "On" set ttoggle to "On" else click radio button "Off" end if end tell end tell if sheet 1 exists then tell sheet 1 click button "Enable Dictation" repeat while sheet 1 exists end repeat end tell end if end tell end tell if ttoggle = "On" then set theProcess to first process whose frontmost is true tell theProcess repeat 2 times key down {command} key up {command} end repeat end tell end if end tell if not sprunning then quit -- optional end tell on error errmsg display notification errmsg with title "Dictation Toggle Error" end try display notification with title "Dictation Toggle" subtitle ttoggle


PS: sorry I have no idea how to properly paste an applescript in these forums. I've seen the following thread and tried several suggestions, but nothing worked correctly. So I just used 'pre' tags. Hints on that in this thread appreciated.


Format AppleScript for Forum Post?

Oct 28, 2014 5:25 AM in response to Loren Ryter

I added this portion (the else part in this if/then block), to kill the daemon, which took up a lot of memory (in my case almost 900 MB), see this thread:


com.apple.SpeechRecognitionCore.speechrecognitiond using significant memory

if ttoggle = "On" then set theProcess to first process whose frontmost is true tell theProcess repeat 2 times key down {command} key up {command} end repeat end tell else -- optionally kill the daemon; comment out if afraid try do shell script "killall -9 com.apple.SpeechRecognitionCore.speechrecognitiond" end try end if

Start dictation with applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.