1
votes

Is it possible to pass a variable from an applescript to an executable bash file? If so, how do I write the executable bash file to accept parameters? I'm going to be passing in a dynamic filename that will get appended to a file path in the executable file.

Applescript...

global A
set A to "test123.pdf"
do shell script "/Users/matt/firstscript " & A 

Bash file...

#!/bin/bash
b64test=$( base64 /Users/matt/Documents/$1) 
echo $b64test | pbcopy
echo $b64test > Users/matt/Base64
1
Are you calling the bash script from within an applescript? - beroe
Yes, see above comment. - Stephen Hammett

1 Answers

4
votes

Your Applescript will need to do something like:

global A
set A to "test123.pdf"
do shell script "/Users/matt/firstscript " & A

Then in your script you can refer to the parameters as $1, $2, etc, or $@ for all of them.

#!/bin/bash

b64_test=$( base64 /Users/matt/Documents/$1)
echo $b64_test | pbcopy
echo $b64_test > /Users/matt/Base64

Note it is not a good idea to name your bash variable test, as this is the name of shell builtin command. All kinds of confusion can ensue.


Alternatively, you should be able to do this without an extra shell script:

set A to quoted form of "/Users/matt/Documents/test123.pdf"
do shell script "base64 " & A & " | pbcopy"