Skip to main content
added necessary information
Source Link
I0_ol
  • 721
  • 2
  • 9
  • 21

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.

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?

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.

Source Link
I0_ol
  • 721
  • 2
  • 9
  • 21

Shell string manipulation not working in Applescript

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?