"Ask for Finder Items" 在 Swift
"Ask for Finder Items" in Swift
我正在尝试打开一个 file-browsing window 类似于屏幕截图中显示的那个,当用户单击"Browse" 按钮。
在 Automator 中,这是通过使用 "Ask for Finder Items" 操作完成的,而在 Swift
中
NSWorkspace().selectFile("\(fileName)", inFileViewerRootedAtPath: "/Library")
打开Finder.app本身的一个新实例;如果我想模拟在 Automator 操作中看到的行为,我应该怎么做?
您正在寻找 NSOpenPanel class. It has several configurable properties for which kinds of files can be selected, and when the user finishes selecting files, you can access them via the URLs
property. You can also read more about it in the File System Programming Guide。
我正在尝试打开一个 file-browsing window 类似于屏幕截图中显示的那个,当用户单击"Browse" 按钮。
在 Automator 中,这是通过使用 "Ask for Finder Items" 操作完成的,而在 Swift
中NSWorkspace().selectFile("\(fileName)", inFileViewerRootedAtPath: "/Library")
打开Finder.app本身的一个新实例;如果我想模拟在 Automator 操作中看到的行为,我应该怎么做?
您正在寻找 NSOpenPanel class. It has several configurable properties for which kinds of files can be selected, and when the user finishes selecting files, you can access them via the URLs
property. You can also read more about it in the File System Programming Guide。