2015-12-28 58 views
0

我在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 

回答

1

在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

+0

非常感謝你!那就是訣竅。 –