You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

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

Created Service to change Dictation Language automatically

Dear All,



With the introduction of Mountain Lion we now have a dictation tool that works well (based on Siri speech recognition). It is for me the best improvement of Mountain Lion as it will increase my productivity in mail and documents during work. However, for my work I have to write mails in Dutch, German and English which means I'll have to change between dictation languages all the time. This is a cumbersom task and for this I've written an AppleScript.


This is what I came up with after 1 day of frustration (I'm completely new to AppleScript):


tell application "System Preferences"


activate

end tell

delay 0.5

tell application "System Events"

tell process "System Preferences"

click menu item "Dictation & Speech" of menu "View" of menu bar 1

tell window "Dictation & Speech"

clickradio button "Dictation" of tab group 1

tell tab group 1

#return value of attribute "AXValue" of pop up button 1

if get value of attribute "AXValue" of pop up button 1 contains "English (United States)" then

tell pop up button 1

click

tell menu 1

click menu item "German"

say "Dictation set to German"

end tell

end tell

else if get value of attribute "AXValue" of pop up button 1 contains "German" then

tell pop up button 1

click

tell menu 1

click menu item "English (United States)"

say "Dictation set to English"

end tell

end tell

end if

end tell

end tell

end tell

end tell


tell application "System Preferences"


quit

end tell


So, after I put this into Automator as a AppleScript to be run as a service I've added in System Preferences\Keyboard\Services a Shortcut to run the script within any application (Mail for example).


All works well, so maybe I'll make someone else happy with my effort (this is also the reason for this somewhat extended introduction and me putting the script in the Mountain Lion forum).


Now my question:


-> If I run the service in Mail, I'll return to the desktop, the system preference change is performed and thereafter I don't return to the mail application. Does anyone know the AppleScript I need to add to make this happen?


I look forward to any reply / help.


Kind regards,



Dennis

MacBook Pro, Mac OS X (10.6.7)

Posted on Aug 1, 2012 10:44 AM

Reply
Question marked as Top-ranking reply

Posted on Aug 1, 2012 3:17 PM

Hi,



Here's the script :

----------------------------------

tellapplication "System Events" tosetpto (path tofrontmost application) asstring


tell application "System Preferences"

activate

reveal anchor "Dictation" of pane "com.apple.preference.speech"

endtell

tell application "System Events"

tell process "System Preferences"

tell pop up button 1 of tab group 1 of window "Dictation & Speech"

click

if (get value of attribute "AXValue") contains "English (United States)" then

click menu item "German" of menu 1

say "Dictation set to German"

else if (get value of attribute "AXValue") contains "German" then

click menu item "English (United States)" of menu 1

say "Dictation set to English"

end if

end tell

endtell

endtell

quit application "System Preferences"

activateapplicationp

----------------------------------


I remove these lines (click menu item "Dictation & Speech" and click radio button "Dictation"), because reveal anchor "Dictation" of pane "com.apple.preference.speech" do the same thing without Gui Scripting.

5 replies
Question marked as Top-ranking reply

Aug 1, 2012 3:17 PM in response to DdeKlerk79

Hi,



Here's the script :

----------------------------------

tellapplication "System Events" tosetpto (path tofrontmost application) asstring


tell application "System Preferences"

activate

reveal anchor "Dictation" of pane "com.apple.preference.speech"

endtell

tell application "System Events"

tell process "System Preferences"

tell pop up button 1 of tab group 1 of window "Dictation & Speech"

click

if (get value of attribute "AXValue") contains "English (United States)" then

click menu item "German" of menu 1

say "Dictation set to German"

else if (get value of attribute "AXValue") contains "German" then

click menu item "English (United States)" of menu 1

say "Dictation set to English"

end if

end tell

endtell

endtell

quit application "System Preferences"

activateapplicationp

----------------------------------


I remove these lines (click menu item "Dictation & Speech" and click radio button "Dictation"), because reveal anchor "Dictation" of pane "com.apple.preference.speech" do the same thing without Gui Scripting.

Created Service to change Dictation Language automatically

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