Macro: Translate selected text using Claude

In my day job, I often get support emails from customers in languages other than English. I have been using the macOS built-in translation tool to interact with these customers, but I was recently talking with my business partner, Many Tricks' founder and coder Peter (no, not the Keyboard Maestro Peter!), who is German.

Peter's English is excellent, and after getting a support email in German, I sent Peter two proposed computer-translated replies: One done by macOS, and one done by Claude. Peter said the Claude translation was notably better. I checked with a French speaking friend, and got the same answer.

Hence, my new macro, which translates the selected text either to English or from any of a a defined list of languages.


NOTE: This macro requires either a paid API key from Anthropic, or a paid subscription to Claude. It also requires a working Claude code installation. The macro makes use of the claude command line tool to do the translations, and that tool requires either a paid API key or a subscription account.

Version 2
Download Macro(s): Translate with Claude.kmmacros (16 KB)

Macro screenshot

Macro notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System information
  • macOS 15.6.1
  • Keyboard Maestro v11.0.4

Old version instructions for posterity's sake

After selecting some text (in any app allowed in the macro's group setup), Control-T launches the macro, which triggers an initial dialog box asking if I'm translating from a language or to my native language:

If I press F [Return], the macro goes to work, and translates the selected text into English—I let Claude figure out what the source language is. When it's done, the translated text appears onscreen, and is copied to the clipboard.

If I press T [Return], then a second prompt appears:

(It's not displayed onscreen, because it wouldn't mean anything to me anyway!).

Usage:

After selecting some text (in any app allowed in the macro's group setup), Control-T launches the macro, which triggers the translation languages list:

image

If you do nothing for three seconds, the macro will translate the selection to English (or whatever is marked as the native language in the macro). If you want to translate what you've written back for a reply to someone, just select a language from the list.

Translations to the native language are displayed onscreen (because it's useful to know what the other person wrote); translations to the foreign language are not (because they'd be meaningless unless you knew the language). Both, though, are copied to the clipboard.

The macro requires you set the path to the claude command, and you can optionally change the native language from English, as well as add additional languages to the translation list. The macro is in a group that only runs in Mail, Messages, Signal, and Safari, which is where I use it; just add more apps to the group's allowed list if desired.

Note that Claude is much slower than the macOS translation tool, but if it means I send our customers easier-to-read messages in their native language, it's worth the added time.

-rob.

1 Like

The first post has been edited, as I uploaded an updated macro. This version dumps the previous To/From dialog, and uses a timeout timer for translations to the defined native language. Less typing, less stuff onscreen, and generally faster and easier to use.

-rob.

What do you mean by Claude code?

By the way, you can get better results by using a specific prompt. Here is an example:

You are a professional technical translator specializing in German to Dutch translation of technical manuals. Your task is to translate the provided German text segments from a manual from the machine manufacturer {client_name} into natural, fluent Dutch. 

Note that you can further improve translation quality by providing a glossary or thesaurus.

It's designed to use in your coding project folders, as it can read and modify source files directly on disk. But for me, it just gives me access to a command line interface to Claude, so I can ask it one-off questions.

While I understand that better prompts can sometimes provide better answers, I definitely don't need a complex prompt for translations from a foreign language—I just need a version I can read that gets the gist of the user's issue across to me. And I've never had any trouble reading the translations based on a simple "Translate this to English" prompt.

As for communicating back to the users, I gave Claude a test: I composed a reply to a user's question and translated it into German. I ran two trials, one with a simple prompt and one with a complex prompt, and the wording of the translations was identical except for three words. I sent it to Peter, and he said either version was fine and they read identically. So I think for my needs, the simple prompt works fine.

I do often use complex prompts, but in this case, it doesn't seem to be necessary. (Perhaps a different prompt focused on expert-to-user interaction would get different results, but I honestly don't have a lot of time to experiment with it right now :)).

-rob.

And (presumably -- not an AI user!) a more complex prompt means more tokens means higher cost per query?

Yea, I'm not sure—I'm just on a pay per month plan, so not sure how it would affect me.

-rob.