Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
动态加载applescript库_Applescript_Shared Libraries - Fatal编程技术网

动态加载applescript库

动态加载applescript库,applescript,shared-libraries,Applescript,Shared Libraries,是否有基于变量加载applescript库的方法。 我努力做到的是: set basescript to "hello.scpt" tell script basescript dialoger("testing") end tell basescript将包含以下内容: on dialoger(message) display dialog message end dialoger 只要我把它打出来,它就工作得很好,但只要我试着像v

是否有基于变量加载applescript库的方法。 我努力做到的是:

set basescript to "hello.scpt"

tell script basescript
    dialoger("testing")
end tell
basescript将包含以下内容:

on dialoger(message)
    display dialog message
end dialoger
只要我把它打出来,它就工作得很好,但只要我试着像var一样传递它,它就会不断地给出错误。。。
非常感谢您的帮助

我一直在使用脚本库。一旦你掌握了窍门,它就会成为一个巨大的省时工具。有几种方法可以将脚本命令从“库脚本”加载到另一个脚本中

一种方法是通过将变量名设置为
load script
path/to/script
来使用
load script
命令

还有另一种方法,在我看来,它更强大。您可以使用
use
语句导入库脚本。此方法不需要使用
tell语句

例如,我在my/Users/your SHORT NAME/Library/Script Libraries/文件夹中将以下代码保存为“Hello.scpt”

on dialoger(message)
    display dialog message
end dialoger
接下来,在我想从库脚本“Hello.scpt”加载命令的脚本中,这是我使用
use语句使用的代码

use basescript : script "Hello"
use scripting additions

basescript's dialoger("testing")
解决方案:


如果您确实将basescript设置为加载脚本POSIX文件“/path/to/Hello.scpt”,那么告诉dialoger basescript(“测试”)将起作用

假设这些是脚本库,您可以使用如下处理程序来完成所需的操作:

-- send the same of the script library in the first parameter
-- and the message in the second

myHandler("hello", "My Message")

on myHandler(libName, message)
    tell script libName
        dialoger(message)
    end tell
end test

由于处理程序直到运行时才被处理,因此它将动态实现在libName中传递的正确脚本库。

这是否回答了您的问题?不,不幸的是没有。这些方法都可以很好地工作,但是当这个脚本名称以变量的形式显示时,它们似乎都不起作用,如上图所示。如果您执行
设置basescript以加载脚本POSIX文件/path/to/Hello.scpt“
告诉basescript给dialoger(“测试”)
将起作用!您的解决方案按建议运行!塔克斯