How to pass a file set as a variable from AppleScript to a Bash shell script 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 &amp; 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 &lt;$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 the gawk command which of course is installed along with the trans 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.
The first problem with the first script is you aren't using the set myFile variable.

Here's a general guide to getting help:

Open Script editor - use the help menu to launch the AppleScript Language Guide and search for the command you have. In this case "do shell script"

That takes you to: https://developer.apple.com/library/prerelease/content/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/CallCommandLineUtilities.html

The example there shows how to set a variable for a host name and then call ping:

set theHostName to "www.apple.com"
do shell script "ping -c1 " &amp; theHostName


So, in your case you'll need:

do shell script "/path/to/script.sh"  &amp; myFile


At that point, you'll likely run into path issues so running small snippets of code in the editor, looking at the result and iterating should get you to solutions as inevitable errors in path, parsing, logic crop up. I left a typo in the second "do shell script" example above - pay attention to spaces and quotes :-)