Start dictation with applescript
Is there a way to start OS X new dictation from AppleScript?
I tried :
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)
Is there a way to start OS X new dictation from AppleScript?
I tried :
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)
I adjusted 2 lines to make this work in Sierra:
reveal pane id "com.apple.preference.speech" change this to
reveal pane id "com.apple.preference.keyboard"
tell window "Dictation & Speech"
change this to : "Keyboard"
thanks to the community for this script!
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.
I made this script for a usb controller, hopefully it's what you're looking for!
tell application "System Events"
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 tell
That's EXACTLY what I was looking for. There's lots of things you can do with the new dictation commands in automator (yosemite), and your script makes turning dictation automatically off afterwards possible.
Thanks
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.
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
seblavoie wrote:
Is there a way to start OS X new dictation from AppleScript?
If you're using Yosemite, there's a new Dictation Command Automator:
Start dictation with applescript