DdeKlerk79

Q: 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"

            click radio 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:45 AM

Close

Q: Created Service to change Dictation Language automatically

  • All replies
  • Helpful answers

  • by Jacques Rioux,Solvedanswer

    Jacques Rioux Jacques Rioux Aug 1, 2012 3:17 PM in response to DdeKlerk79
    Level 4 (3,418 points)
    Mac OS X
    Aug 1, 2012 3:17 PM in response to DdeKlerk79

    Hi,

     

     

    Here's the script :

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

    tell application "System Events" to set p to (path to frontmost application) as string

     

    tell application "System Preferences"

        activate

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

    end tell

    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

        end tell

    end tell

    quit application "System Preferences"

    activate application p

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

     

    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.

  • by Wilfried Kaiser,

    Wilfried Kaiser Wilfried Kaiser Aug 5, 2012 4:21 AM in response to Jacques Rioux
    Level 1 (0 points)
    Aug 5, 2012 4:21 AM in response to Jacques Rioux

    Can you give me a hint of how to install this as an Service or even better as an Automator App directly into my Dock? I also need constant switching between English and German.

  • by Brian Yip,

    Brian Yip Brian Yip Sep 20, 2012 8:08 PM in response to Wilfried Kaiser
    Level 1 (9 points)
    Apple Watch
    Sep 20, 2012 8:08 PM in response to Wilfried Kaiser

    Apple should include a build-in support for quickly change language for dictation. Or just follow on the text input language, sth similar to iOS dictation...

  • by Tom Gewecke,

    Tom Gewecke Tom Gewecke Sep 21, 2012 3:19 AM in response to Brian Yip
    Level 9 (79,474 points)
    Sep 21, 2012 3:19 AM in response to Brian Yip

    Brian Yip wrote:

     

    Apple should include

     

    Let them know at

     

    http://www.apple.com/feedback/

  • by Luds,Helpful

    Luds Luds Mar 2, 2013 10:17 AM in response to DdeKlerk79
    Level 1 (5 points)
    Mar 2, 2013 10:17 AM in response to DdeKlerk79

    Message for DdeKlerk79, not sure if this helps but someone developped a "Dictation Switcher" a little utility that sits in your Mac's menu bar and makes using Dictation even easier. it can be found here: http://fouquet.me/apps/dictationswitcher/

     

    Understand you had the pleasure to write your own script but just in case, I thought this might help...