I receive many emails in Japanese everyday (I am living in Japan). Some are spam but some are important. I would like to have an AppleScript to do the following
- Translate the email (with google translate for example)
- Forward back the translated email to my own email account
In this way, I will save the time to translate every email every day to understand which one is important and which one is not…
I think this can be done with AppleScript. I can make a rule in Mail to run an AppleScript every time that I receive a message from a certain mail account. I checked and it worked. But the problem is I am not able to write the AppleScript. I am not familiar with AppleScript, and honestly, I don't know where to start!
Edit:
Alternatively, the translation can be also done with another software, which can be installed locally. Free or non free software does not matter.
Best Answer
I've created an automator workflow that uses AppleScript and Bash to do what you want.
There are two steps to implementation:
translate-shell
You could probably use steps 1-2 to make a more specifically tailored applescript to copy the entire email and translate it, but I made a sample workflow that you could use just in case.
1: installation
translate-shell
uses a number of different engines to translate using terminal. You don't have to understand most of this, just that you'll be using terminal to install it.Go to the github page and install it: There are many ways to do this, but here is one
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
and hit enterbrew install gawk
and hit entergit clone https://github.com/soimort/translate-shell
cd translate-shell/
make
make install
(if this line doesn't work, trysudo make install
and then type in your password.Everything should now be installed in step 1
2: create an automator workflow – this is where the applescript is
paste in the following script exactly as shown:
on run {input, parameters} tell application "System Events" key code 8 using command down end tell set theText to the clipboard set theTranslation to (do shell script "export PATH=\"/usr/local/bin:$PATH\";/usr/local/bin/trans -b :en " & quoted form of theText) display dialog theTranslation end run
translate-shell
translate the text to English and display it.3: Create a shortcut
If you'd rather highlight and use a shortcut, just create a shortcut to activate the workflow and translate any highlighted text. It's well documented in many places, but here's one stack exchange post where you can find the information.
Notes:
brew install --HEAD translate-shell
which is worth a shot