bash 如何使用参数打开 AppleScript 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29258142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How Can I Open AppleScript App with Arguments
提问by T Varcor
I Have an AppleScript that runs a Scan Program (commandline) that scans to a specific folder. I need to pass arguments to the applescript that in-turn passes the arguments to the terminal.
我有一个 AppleScript,它运行扫描到特定文件夹的扫描程序(命令行)。我需要将参数传递给 applescript,后者又将参数传递给终端。
In a terminal I want to run open -a /Applications/MyScanApp.app myargument
and the AppleScript runs. How can I pass that argument? Thank You for Your Help! I am normally a PHP programmer and this is something completely different to me.
在我想运行的终端中open -a /Applications/MyScanApp.app myargument
,AppleScript 运行。我怎么能通过这个论点?感谢您的帮助!我通常是一名 PHP 程序员,这对我来说完全不同。
My AppleScript:
我的 AppleScript:
tell application "Terminal"
do script "./myscanprogram myargument 2>&1"
end tell
回答by dj bazzie wazzie
Why doesn't anyone mention quoted form of
? When you want to send arbitrary data as an argument to an application you should use quoted form of. When quotes, spaces and other special characters are in the given path the command will break down in de previous examples.
quoted form of
怎么没人提?当您想将任意数据作为参数发送到应用程序时,您应该使用引用的形式。当引号、空格和其他特殊字符位于给定路径中时,该命令将在前面的示例中分解。
on run argv
tell application "Terminal"
do script "./myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
end tell
end run
Since you mentioned you're new to AppleScript does it have to run in the Terminal.app or is a shell enough? AppleScript has the command do shell script
which opens a shell, execute the text and return the stdout back to you.
既然你提到你是 AppleScript 的新手,它是否必须在 Terminal.app 中运行还是一个 shell 就足够了?AppleScript 具有do shell script
打开外壳、执行文本并将标准输出返回给您的命令。
on run argv
do shell shell script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
end run
Last but not least. If you don't want the output of the scan program and don't want AppleScript to wait until it's finished you can use
最后但并非最不重要的。如果您不希望扫描程序的输出并且不希望 AppleScript 等到它完成,您可以使用
on run argv
do script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " &>/dev/null &"
end run
回答by ShooTerKo
Wondering why you're using your Terminal to address an AppleScript that uses the Terminal again, but maybe I just don't know your circumstances...
想知道您为什么要使用终端来解决再次使用终端的 AppleScript,但也许我只是不知道您的情况......
Applescript:
苹果文字:
on run argv
tell application "Terminal"
do script "./myscanprogram " & (item 1 of argv) & " 2>&1"
end tell
end run
Call from osascriptinside your Terminal:
从终端内的osascript调用:
osascript pathToYourScript.scpt myargument