在Applescript中设置对象的属性值Objective-C
问题描述:
我在OSX 10.9.5的XCode(5)中工作,创建一个ApplescriptOjbC项目。在Applescript中设置对象的属性值Objective-C
我在项目中创建了一个名为“MSDropBox”的类(脚本),并使用它接受文件的拖放。丢弃的文件的文件路径读取正确。我现在只想把这个数组传递给Array控制器,该控制器用作表的源。我想让表格反映拖动的文件。
我有一个AppDelegate类中设置值的方法,我从MSDropBox类调用它。但是,它正在影响表中的值。我相信它正在呼唤班级的方法,但不是反对。我如何影响对象?
下面是MSDropBox类:
script MSDropBox
property parent : class "NSBox"
property window : missing value
property thisPageList : missing value
on draggingEntered_(sender)
log "entered"
set pb to sender's draggingPasteboard()
set theOptions to {NSPasteboardURLReadingFileURLsOnlyKey:1}
return pb's canReadObjectForClasses_options_({current application's |NSURL|}, theOptions)
end draggingEntered_
on performDragOperation_(sender)
log "perform"
-- Get the file paths
set pb to sender's draggingPasteboard()
set theOptions to {NSPasteboardURLReadingFileURLsOnlyKey:1}
set theURLs to pb's readObjectsForClasses_options_({current application's |NSURL|}, theOptions)
log theURLs
repeat with thisURL in theURLs
set thisURLStr to (characters 1 thru -1 of ((thisURL's |path|()) as string) as string)
set thisPageList to thisPageList & thisURLStr as list
end repeat
return true
end performDragOperation_
on concludeDragOperation_(sender)
log "concludeDragOperation_"
tell class "AppDelegate" of current application
setPageList_(thisPageList)
end tell
end concludeDragOperation_
end script
答
在Objective-C是
AppDelegate *appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
[appDelegate setPageList:thisPageList];
的AppleScriptObjC相当于是
set appDelegate to current application's NSApplication's sharedApplication()'s delegate()
appDelegate's setPageList_(thisPageList)
我不知道AppleScriptObjC是否可以识别应用委托方法无需类型转换,也许您必须添加as AppDelegate
非常感谢你!那就是诀窍。 –