GUI for “Translate Shell”



This macro is a GUI wrapper the the excellent Translate Shell script by Mort Yao.

The great thing with Translate Shell is that it works with many different translation engines, for example Google, Bing, Yandex and —since a couple of days— also with the fine DeepL engine.

You get all in one, without the need for different scripts.

The Translate Shell script works perfectly fine in the Terminal, so this macro is really just a “convenience” macro that provides a bit more comfort.


  • Text is copied automatically.
  • You can query up to three translation engines simultaneously.
  • You can query translations to different target languages simultaneously.
  • Optionally you can choose the target language from a quick list prompt.

This macro covers only the main use-case, that is, translating junks of text. Translate Shell has many more little great features that are not accessible through the macro, and some of them are designed to be run in the Terminal.

It is really worth to read through the documentation on GitHub!


Of course you need to have Translate Shell installed on your Mac. Fortunately this can be done via Homebrew:

brew install --HEAD translate-shell

The --HEAD switch installs the most recent version, which currently (2017-12-16) is the only one that includes the DeepL engine. To install the “stable” release just omit that switch.


  1. Select the text to translate in your word processor or text editor.
    • If nothing is selected the clipboard content will be used.
  2. Launch the macro from the Global palette.
    • The translations will be displayed in one or more KM windows.

Settings / First run

On the first run of the macro you will be presented with the Settings prompt:

I think the prompt is pretty much self-explanatory.

Some notes:

  • Target language: Use two-letter ISO codes. If you leave this field empty the system language of your Mac will be the target language. Combine multiple languages with a +
  • Source language: In most cases “Auto” is fine.
  • Engine: This is the only setting you have to set.
  • Engine 2, Engine 3: Additional engines to query. The results of each engine will be displayed in a separate window. To disable the additional engines set them to “None” or just deselect the checkbox.

After the first run (and you have selected an engine) the Settings prompt will not appear again.

:high_brightness: To bring up the Settings prompt again launch the macro with the Command (⌘) key pressed. :high_brightness:

List prompt

If you are frequently switching between different target languages, you have the option to activate a quick selection via a List Prompt:

To activate the List Prompt, bring up the Settings window and enter “list” in the “Target language” field:

:bomb: Issues & Troubleshooting

  • Make sure the ENV_PATH variable is correctly set in KM.
  • If you get encoding issues, then set KM’s ENV_LANG variable to something UTF-8, for example en_US.UTF-8
  • When using the DeepL engine there seem to be encoding issues on the Mac, no matter how the LANG variable is set.

Workaround for the DeepL encoding issue

To get correct UTF-8 chars with DeepL simply append (without newline) this to the existing script in the Shell Script action (including the | at the beginning):

| perl -Mopen=':std',':encoding(UTF-8)' -pe '$_ =~ s/\\u(.{4})/chr(hex($1))/eg;'

Note that this is only necessary if you are using DeepL and you are dealing with non-ASCII chars (that is, translating to other languages than English). Google and the other engines work fine without it.

This is meant as a temporary workaround until the issue gets solved by Translate Shell itself.



Translate via Translate Shell.kmmacros (22.1 KB)

Translate via DeepL
Translation macro
How to create a macro which uses google translate with pdf documents, and functions just like the google translate chrome extension
Translate via DeepL

Update 2018-06-05

In the section “Issues & Troubleshooting” of the post above I have mentioned a Perl workaround to make the Translate Shell script work correctly with non-ASCII chars from the DeepL engine.

As I have learned today, that workaround is no longer necessary if you use…

  • the current version of the Translate Shell script ( and
  • install a current version of bash (4.4.23)

The bash that comes with macOS High Sierra is version 3.2.57. You can install bash 4 with Hombrew:

brew install bash

This will currently install bash 4.4.23. For the purpose of the macro it is not necessary to add anything to /etc/shells

If you prefer not to install bash 4 you can of course still use the Perl fix as shown in the post above.


Tom, as you know I am a shell scripting / bash neophyte (not even that good).
I don't need your Translate Shell stuff, but should I upgrade to bash 4 anyway?

If so, does it completely replace the current version? Is there anything special I need to do after the upgrade?

And finally, will bash 4 keep me out of trouble? LOL

As always, thanks for your valuable guidance.


I don’t now. The relevant stuff in the case here is a better/different Unicode handling by bash 4, told me the author of Translate Shell.

Besides that I have no clue what the major differences are. I also worked with bash 3 till now.

Here are the complete release notes covering bash 2 through 4.4. — I’m going to read them… one of these days :wink:

If so, does it completely replace the current version?

You can uninstall it at any time with brew uninstall bash. Then the old, preinstalled bash 3 will be used. (Bash 4 via Hombrew will go to /usr/local/bin, whereas the system’s bash 3 is in /bin. So nothing gets overwritten or so.)

Is there anything special I need to do after the upgrade?

Hombrew says, for full usage in the interactive shell the path of bash 4 should be added to /etc/shells. I think this is a security thingy.

As long as you have set your Terminal to use the default login shell (see screenshot below) and /usr/local/bin is on your PATH it will be used by the Terminal automatically.

Terminal prefs, General tab:


Similar of course for KM: /usr/local/bin must be in your ENV_PATH variable. But I guess it is there already, otherwise KM would not find any of your Homebrew-installed tools.