从AppleScript的传递变量可执行文件的bash [英] Pass variable from applescript to executable bash file
问题描述
是否有可能从一个AppleScript一个变量传递给一个可执行文件的bash?如果是这样,我怎么写的可执行文件的bash接受参数?我要被传递,将获得附加到文件路径中的可执行文件动态文件名。
AppleScript的...
全球一
一组为test123.pdf
做shell脚本/用户/亚光/ firstscript&放大器;一个
Bash的文件...
#!/斌/庆典
b64test = $(BASE64 /用户/亚光/文件/ $ 1)
回声$ b64test | pbcopy
回声$ b64test>用户/亚光/ Base64编码
您的AppleScript将需要做的是这样的:
全球一
一组为test123.pdf
做shell脚本/用户/亚光/ firstscript&放大器;一个
然后在你的脚本,你可以参考参数 $ 1
, $ 2
等,或 $ @
它们。
#!/斌/庆典b64_test = $(BASE64 /用户/亚光/文件/ $ 1)
回声$ b64_test | pbcopy
回声$ b64_test> /用户/亚光/ Base64编码
请注意这不是一个好主意来命名的bash变量测试
,因为这是shell内建命令的名称。种种困惑可以随之而来。
另外,你应该能够做到这一点无需额外的shell脚本:
设定为/Users/matt/Documents/test123.pdf的形式引用
做shell脚本的base64&放大器;急症室; | pbcopy
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
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"
这篇关于从AppleScript的传递变量可执行文件的bash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!