I'm trying to make a service to translate things which Chrome doesn't translate automatically. The following script works when run from my shell
#!/bin/bash
input='это тест)))' # translates to - this is a test)))
if [[ $(echo "$input") =~ ')' ]]; then
input="$(echo "${input//)/}")"
fi
export PATH="/usr/local/bin:$PATH"; /usr/local/bin/trans -e yandex -b :en "$input"
the result: this is a test
However when I put this into an Applescript:
set input to "это тест)))"
set output to (do shell script "if [[ $(echo " & quoted form of input & ") =~ ')' ]]; then " & quoted form of input & "=\"$(echo \"${" & quoted form of input & "//)/}\")\"; fi; export PATH=\"/usr/local/bin:$PATH\"; /usr/local/bin/trans -e google -b :en " & quoted form of input & "")
display dialog output as string
The result is still this is a test)))
It still runs and translates the input string. But it doesn't remove the )))
. I don't understand why the if
statement is not working in my applescript version. Am I quoting something wrong?
This script uses a program called Translate-Shell which can be found on GitHub or at the program author's website here.
trans
come from as it's not a native OS X app included in the OS X installation, so I'm unable to reproduce your command line for testing. Is there a native OS X binary available from somewhere or the source code so I can compile it directly as I don't use the typical package managers, e.g Homebrew?trans
is translate-shell which can be found on GitHub or at the authors own website here.