我一直在想如何将多个参数从Applescript传递给终端命令脚本。例如运行终端命令文件时,您可以以编程方式接收参数,像这样:从AppleScript传递多个参数到终端命令脚本
#!/bin/bash
var=$1
var=$2
,我一直在使用的AppleScript的代码如下供参考:
tell application "System Events" to set app_directory to POSIX path of (container of (path to me))
set thisFile to "Dev"
set testTarget to "/Users/lab/Desktop/TestTarget/"
do shell script "/Users/lab/Desktop/TempRoot/mycommand.command " & thisFile & testTarget with administrator privileges
在哪里,我想我出错了是第二个参数的输入。当我只有一个参数时,它通过了很好:
do shell script "/path/to/command/mycommand.command" &var with administrative privileges
我很好奇什么正确的语法将传递在这第二个参数。如果有人有任何建议,请让我知道!另外如果您需要更多信息,我会很乐意提供!
这工作!我会upvote这篇文章,但显然我没有足够的stackoverflow点:(但非常感谢你! – mmilutinovic1313 2015-03-03 14:56:21
@ mmilutinovic1313:你不需要声望点_accept_ _yours_问题的答案(点击复选标记)。 – mklement0 2015-03-03 17:10:56
另一个值得一提的提示是:为了确保字符串(如文字)文件名被传递到未经修改的shell(为了保护字符串不受shell扩展),以“'quoted form of”作为前缀。 – mklement0 2015-03-03 17:13:09