如何从终端启动 applescript.scpt 文件并传递术语/变量?
我有一个 applescript 可以执行以下操作:
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 文件并传入一个变量,例如路径到一个文件。
osascript ~/applescript.scpt /path/to/my/file.txt
然后让 Applescript 运行并访问该参数。在这种情况下,它(希望)会显示一个包含该路径的对话框, /path/to/my/file.txt
我知道我可以通过执行类似的操作来实现这一目标
osascript -e "display dialog "~/path/to/file.txt"
,但重点不是显示与 Applescript 的对话,更多的是了解我是否能够将变量传递到脚本文件中。
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
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
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"
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在脚本中,您可以使用
on run
传递参数,如下所示:如果指定了多个参数,则
arg
变量是一个列表。In the script you pass in the arguments with the
on run
like this :If more than one argument is specified the
arg
variable is a list.