如何使用命令编译applescript,如;编撰;从「;Applescript编辑器“;

如何使用命令编译applescript,如;编撰;从「;Applescript编辑器“;,applescript,Applescript,我有两个苹果脚本: parent.scpt: 物业a:1 child.scpt: 属性父级:加载脚本POSIX文件“../parent.scpt” 返回一个 我在parent.scpt中将a的值更改为“2”,运行“sudo osacile…/child.scpt”,然后运行“sudo osascript…/child.scpt” 它仍然得到值“1”,但是如果我从“AppleScript编辑器”中“编译”child.scpt,我可以得到正确的值“2” 我错过什么了吗?如何使用命令实现此目的?在重新

我有两个苹果脚本:

parent.scpt:
物业a:1

child.scpt:
属性父级:加载脚本POSIX文件“../parent.scpt”
返回一个

我在parent.scpt中将a的值更改为“2”,运行“sudo osacile…/child.scpt”,然后运行“sudo osascript…/child.scpt” 它仍然得到值“1”,但是如果我从“AppleScript编辑器”中“编译”child.scpt,我可以得到正确的值“2”


我错过什么了吗?如何使用命令实现此目的?

在重新编译脚本之前,属性是持久的。如果在设置属性时加载脚本文件,则在编译时而不是运行时加载。这意味着将存储脚本的副本,并且属性与文件无关。它使用脚本编辑器的原因是重新编译文件,这意味着parent.scpt将再次加载到最新版本

我不建议加载父对象,最好加载子对象。现在从父级链的底部开始,最好从根对象开始构建对象树

查看您的代码,您试图在对象树中动态添加对象。一种方法是:

parent.scpt:

property name : "I'm the parent"
property b : 100

set theChildLib to load script POSIX file "/Users/shortname/Desktop/child.scpt"
set theChild to theChildLib's newChildObject(me)
return {theChild's parent's name, theChild's name, theChild's a, theChild's b}
child.scpt:

on newChildObject(_parent)
    script childObject
        property parent : _parent
        property name : "I'm the child"
        property a : 2
    end script
    return childObject
end newChildObject

正如你所看到的,我可以从孩子那里给父母打电话。当我调用一个对象中不存在的属性时,它将遵循父项链

在重新编译脚本之前,属性是持久的。如果在设置属性时加载脚本文件,则在编译时而不是运行时加载。这意味着将存储脚本的副本,并且属性与文件无关。它使用脚本编辑器的原因是重新编译文件,这意味着parent.scpt将再次加载到最新版本

我不建议加载父对象,最好加载子对象。现在从父级链的底部开始,最好从根对象开始构建对象树

查看您的代码,您试图在对象树中动态添加对象。一种方法是:

parent.scpt:

property name : "I'm the parent"
property b : 100

set theChildLib to load script POSIX file "/Users/shortname/Desktop/child.scpt"
set theChild to theChildLib's newChildObject(me)
return {theChild's parent's name, theChild's name, theChild's a, theChild's b}
child.scpt:

on newChildObject(_parent)
    script childObject
        property parent : _parent
        property name : "I'm the child"
        property a : 2
    end script
    return childObject
end newChildObject

正如你所看到的,我可以从孩子那里给父母打电话。当我调用一个对象中不存在的属性时,它将遵循父项链

如果有人遵循我的示例,我想出了一个简单的解决方案:将代码从child.scpt复制到一个纯文本文件child.txt,在每次运行“sudo osascript child.scpt”之前运行“sudo osascript child.txt”,或者只运行“sudo osascript child.txt”如果有人遵循我的示例,我想出了一个简单的解决方案:将代码从child.scpt复制到一个纯文本文件child.txt,在每次运行“sudo osascript child.scpt”之前运行“sudo osascript child.txt”,或者只运行“sudo osascript child.txt”