I've got a two part problem.
- I am trying to pass a variable from AppleScript to be used as a variable inside a bash shell script. I cannot figure out how to this work. I have read about concatenating the variable and the
do shell script
command with&
inside AppleScript. But that doesn't really work with a longer script.
Here is the short AppleScript to select a file and (hopefully) pass it along to the shell as a variable.
tell application "Finder"
activate
choose file
set myFile to result as text
end tell
do shell script "/path/to/script.sh"
And then the shell script itself:
#!/bin/bash
while read lines
do
echo ${lines##*:}
grep "string"
done <$myFile | awk '!x[$0]++' |\
trans -b :en # this is where the second problem occurs
This is a shortened version of the actual script but I think the intent is clear. I am unsure how to pass the myFile
variable FROM Applescript to the shell.
- The second problem is that the
trans
command (which is a rather handy command line translator) uses thegawk
command which of course is installed along with thetrans
program itself. But when run from Applescript I get the error message:
error "/usr/local/bin/trans: line 4990: gawk: command not found" number 127
I know that AppleScript needs the fullpath in order for this to work. But how do I provide the full path for a command embedded deep within nearly 5000 lines of code? Do I alter the code of the trans
program itself to provide the full path to gawk
?
Also I realize that I could do the whole thing from within the shell and that a lot of this is adding complexity where none is needed. But I think it is still worthwhile to know how to do this.
Thanks for reading.