// Place the following code within your Document subclass
// enable or disable the menu item called "Show in Finder"
override func validateUserInterfaceItem(anItem: NSValidatedUserInterfaceItem) -> Bool {
if anItem.action() == #selector(showInFinder) {
return self.fileURL?.path != nil;
} else {
return super.validateUserInterfaceItem(anItem)
}
}
// action for the "Show in Finder" menu item, etc.
@IBAction func showInFinder(sender: AnyObject) {
func showError() {
let alert = NSAlert()
alert.messageText = "Error"
alert.informativeText = "Sorry, the document couldn't be shown in the Finder."
alert.runModal()
}
// if the path isn't known, then show an error
let path = self.fileURL?.path
guard path != nil else {
showError()
return
}
// try to select the file in the Finder
let workspace = NSWorkspace.sharedWorkspace()
let selected = workspace.selectFile(path!, inFileViewerRootedAtPath: "")
if !selected {
showError()
}
}
"come visualizzare una finestra di ricerca di tale directory"? – onmyway133
Eventuali duplicati di [lancio finestra OSX Finder con file specifici selezionati] (http://stackoverflow.com/questions/7652928/launch-osx-finder-window-with-specific-files-selected) – Eonil