Is it possible to bind my Mac OSX Dictionary.app to Google Translate?

Solution 1:

Unfortunately it doesn't appear to be possible, or at least straightforward. As an alternative, you may want to consider creating an OS X Service that opens Google Translate in a browser window, for any highlighted word or phrase you have selected.

If this sounds suitable, follow the procedure below:

Creating a translation Service

  • Open the Automator app from your Applications folder
  • Select Service as the type of document and click Choose
  • In the window that appears, click the search field and type 'AppleScript'
  • Drag and drop the Run AppleScript action from the list on the left into the area labelled 'Drag actions or files here to build your workflow'

Copy the script below and paste it into the Run Applescript action:

on run {input, parameters}
    set phrase to input as string
    set phrase to quoted form of phrase

    set ui_lang to "en"
    set from_lang to "en"
    set to_lang to "zh-CN"

    do shell script "open 'https://translate.google.com/?hl='" & ui_lang & "'&sl='" & from_lang & "'&tl='" & to_lang & "'&text='" & phrase
end run

Your window should look like the following:

Automator workflow

There are three values that you may want to change in the above script:

  • ui_lang - the language used for the page interface
  • from_lang - the source language
  • to_lang - the destination language

Change one or more of these to achieve the desired translation. To find the correct language parameters, refer to the Language Reference. In the example above en refers to English, and zh-CN to Chinese (Simplified).

After making your changes, click File > Save... and in the panel that appears type a suitable name (e.g. Translate English to Chinese).


Using the translation Service

After saving your workflow above, you can make use of your translation service with one of the following two methods:

1. The Service Menu method

  • Highlight a word or phrase in any application
  • Click the Application Menu to the right of the Apple icon (), then click Services and Translate English to Chinese (or the name you gave your Service when saving it):

Service menu example

2. The Contextual Menu method

  • Highlight a word or phrase in any application
  • Right-click the text and select Services then Translate English to Chinese (or your custom named Service):

Contextual menu example


Whichever method you use, a browser window should appear with your translated text:

Google Translate example

Solution 2:

This one does everything like the soulcake's answer but if the translater's url is already present - loads new translation in the same tab

on run {input, parameters}
    set phrase to input as string

    set ui_lang to "en"
    set from_lang to "en"
    set to_lang to "ru"

    set theBaseUrl to "https://translate.google.com/"
    set theUrl to theBaseUrl & "?hl=" & ui_lang & "&sl=" & from_lang & "&tl=" & to_lang & "&text=" & phrase

    tell application "Google Chrome"
        activate

        if (count every window) = 0 then
            make new window
        end if

        set found to false
        set theTabIndex to -1
        repeat with theWindow in every window
            set theTabIndex to 0
            repeat with theTab in every tab of theWindow
                set theTabIndex to theTabIndex + 1
                if theTab's URL starts with theBaseUrl then
                    set found to true
                    exit repeat
                end if
            end repeat

            if found then
                exit repeat
            end if
        end repeat

        if found then
            set URL of theTab to theUrl
            set theWindow's active tab index to theTabIndex
            set index of theWindow to 1
        else
            tell window 1 to make new tab with properties {URL:theUrl}
        end if
    end tell

end run