Skip navigation

Created Service to change Dictation Language automatically

1193 Views 5 Replies Latest reply: Mar 2, 2013 10:17 AM by Luds RSS
DdeKlerk79 Calculating status...
Currently Being Moderated
Aug 1, 2012 10:45 AM

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)
  • Jacques Rioux Level 4 Level 4 (1,925 points)

    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.

  • Wilfried Kaiser Calculating status...

    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.

  • Brian Yip Calculating status...

    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...

  • Tom Gewecke Level 9 Level 9 (70,850 points)

    Brian Yip wrote:

     

    Apple should include

     

    Let them know at

     

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

  • Luds Level 1 Level 1 (5 points)

    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...

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.