1

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
2
  • Are you calling the bash script from within an applescript? Commented Feb 6, 2014 at 0:33
  • Yes, see above comment. Commented Feb 6, 2014 at 19:21

1 Answer 1

4

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"
Sign up to request clarification or add additional context in comments.

9 Comments

@StephenHammett - in general, it is better to edit your question, rather than post code in comments
@StephenHammett - see my edited answer - specifically I didn't realise at first you needed to pass the value of an applescript variable
@StephenHammett - also no need to ask another question - this one can be edited sufficiently to meet needs.
I made your recommended changes. Please see above.
@StephenHammett - oops - its a & instead of a + needed to concatenate strings. Sorry about that.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.