在您重新編譯腳本之前,屬性是持久的。如果您在設置屬性時加載腳本文件,則在編譯時完成,而不是在運行時完成。這意味着腳本的副本被存儲並且屬性與文件無關。它與腳本編輯器一起工作的原因是該文件被重新編譯,這意味着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「 –