【问题标题】:Setting Property Value of Object in Applescript Objective-C在 Applescript Objective-C 中设置对象的属性值
【发布时间】:2016-04-02 17:43:23
【问题描述】:

我正在使用 OSX 10.9.5 上的 XCode (5) 创建一个 ApplescriptOjbC 项目。

我在项目中创建了一个新的applescript,其中包含一个名为“MSDropBox”的类(脚本),并使用它来接受文件的删除。删除的文件的文件路径读取正确。我现在只想将此数组传递给数组控制器,它用作表的源。我希望表格反映拖动的文件。

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

【问题讨论】:

    标签: xcode macos xcode5 nstableview applescript-objc


    【解决方案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

    【讨论】:

      猜你喜欢
      • 2012-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-24
      • 2016-10-27
      • 2023-03-10
      • 2011-12-16
      相关资源
      最近更新 更多