如何从终端启动applescript.scpt文件并传递术语/变量? [英] How can I launch an applescript.scpt file from the terminal and pass terms / variables?

查看:990
本文介绍了如何从终端启动applescript.scpt文件并传递术语/变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序执行这些行:

 使用应用程序中的术语Quicksilver
打开这些项目
在这些项目中用aitem重复
显示对话框aitem作为文本
结束重复
结束打开
结束使用
中的术语

但我想做的是能够开始运行一个特定的 applescript.scpt 文件,并传递一个变量,例如文件的路径。

  osascript〜/ applescript.scpt / path /to/my/file.txt 

,然后运行Applescript以访问该参数。在这种情况下,(希望)显示一个具有该路径的对话框, /path/to/my/file.txt



我知道我可以通过做一些像

  osascript -e显示对话框〜/ path / to / file.txt

但是要点不是显示一个带有Applescript的对话框,

解决方案

在脚本中,你传递参数和在运行如下:

  -do any you want with arg 
end run

如果指定了多个参数 arg 变量是一个列表。




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.

解决方案

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

If more than one argument is specified the arg variable is a list.

这篇关于如何从终端启动applescript.scpt文件并传递术语/变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆