我正在尝试弄清楚如何通过拖放文件或文件夹来启动OSX上的Swift应用程序,并将其作为参数处理所拖放资源的完整路径。
我正在尝试弄清楚如何通过拖放文件或文件夹来启动OSX上的Swift应用程序,并将其作为参数处理所拖放资源的完整路径。
AppDelegate.swift
文件中,添加application(_:openFile:)
函数。@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
func application(_ sender: NSApplication, openFile filename: String) -> Bool {
print("openning file \(filename)")
// You must determine if filename points to a file or folder
// Now do your things...
// Return true if your app opened the file successfully, false otherwise
return true
}
}
public.jpeg
,它是public.image
的子分支,而public.image
又是public.data
的子分支,以此类推。有关更多信息,请参见Uniform Type Identifier Overview和System-Declared Uniform Type Identifiers。mdls
。mdls -name kMDItemContentTypeTree /path/to/file_or_folder