使用 choose file with choose file sheet (如在 NSOpenPanel 中)

Use choose file with choose file sheet (as in NSOpenPanel)

我想知道是否可以使用像 "Choose file sheet" 这样的选择文件,如果答案是肯定的,你能举个例子吗?

表单使用 AppleScriptObjC 有点麻烦,但 Myriad Helpers 有很大帮助。 要使用 NSOpenSave+MyriadHelpers 类别,请使用 File > Add Files to …[=16 将它们的 .h 和 .m 文件添加到您的 Xcode 项目中=] 菜单项。例如,从一个新的(默认)AppleScript 应用程序项目,您可以执行以下操作:

on applicationDidFinishLaunching_(aNotification)
    tell current application's NSOpenPanel's openPanel()
        its setMessage:"Please select a file:"
        its setPrompt:"Choose"
        its setDirectoryURL:(current application's NSURL's fileURLWithPath:(POSIX path of (path to desktop)))

        its setCanChooseFiles:true
        its setCanChooseDirectories:false
        its setAllowsMultipleSelection:true
        its setAllowedFileTypes:{"png"} -- list of extensions or UTIs

        its showOver:theWindow calling:{"panelCompletion:", me}
    end tell
end

on panelCompletion:openItems
    if openItems is missing value then -- "Cancel" button
        log "Cancel"
        return -- or whatever
    end if
    repeat with anItem in openItems as list
        log anItem -- do your thing with the individual file paths
    end repeat
end panelCompletion: