如何从终端启动 applescript.scpt 文件并传递术语/变量? [英] How can I launch an applescript.scpt file from the terminal and pass terms / variables?
问题描述
我有一个苹果脚本,可以做一些类似的事情:
I have an applescript that does something along these lines:
using terms from application "Quicksilver"
on open theseitems
repeat with aitem in theseitems
display dialog aitem as text
end repeat
end open
end using terms from
但我想做的是能够通过终端开始运行特定的 applescript.scpt
文件并传入一个变量,比如文件的路径.
But what I'd like to do is be able to start running a particular applescript.scpt
file via the Terminal and pass in a variable, like a path to a file.
osascript ~/applescript.scpt /path/to/my/file.txt
然后让 Applescript 运行并访问该参数.在这种情况下,它会(希望)显示一个带有该路径的对话框,/path/to/my/file.txt
and then have the Applescript run with access to that parameter. In this case it would (hopefully) display a dialog with that path, /path/to/my/file.txt
我知道我可以通过做类似的事情来实现这一点
I know I could achieve that by doing something like
osascript -e "display dialog "~/path/to/file.txt"
但重点不是用 Applescript 显示对话框,而是更多地了解我是否能够将变量传递给脚本文件.
But the point is not to display a dialog with Applescript, rather it's more about knowing if I would be able to pass a variable in to a script file.
推荐答案
在脚本中,您使用 on run
传递参数,如下所示:
In the script you pass in the arguments with the on run
like this :
on run arg
--do whatever you want with arg
end run
如果指定了多个参数,arg
变量是一个列表.
If more than one argument is specified the arg
variable is a list.
这篇关于如何从终端启动 applescript.scpt 文件并传递术语/变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!