在您重新编译脚本之前,属性是持久的。如果您在设置属性时加载脚本文件,则在编译时完成,而不是在运行时完成。这意味着脚本的副本被存储并且属性与文件无关。它与脚本编辑器一起工作的原因是该文件被重新编译,这意味着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 osacompile -o child.scpt child.txt”每次运行之前“sudo osascript孩子.scpt“,或者运行”sudo osascript child.txt“ –