3

I've tried this:

var openedSuccessfully = AppKit.NSWorkspace.SharedWorkspace.OpenFile(filePath);

It seems to work, except for those file types which have no default app associated with them. When I try to open such a file from Finder, I get this dialog:

Finder's app chooser

Is there a way to programatically open this (or similar) app chooser window?

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
nvirth
  • 1,599
  • 1
  • 13
  • 21

2 Answers2

8

Try the openFile:withApplication method, setting the application to Finder. That should open the app chooser window, or the default app, as appropriate.

// Opens app chooser
AppKit.NSWorkspace.sharedWorkspace().openFile(unknownFile, withApplication: "Finder") 
// Opens default application
AppKit.NSWorkspace.sharedWorkspace().openFile(knownFile, withApplication: "Finder")

Xamarin.Mac Format:

NSWorkspace.SharedWorkspace.OpenFile(knownFile, "Finder");
SushiHangover
  • 73,120
  • 10
  • 106
  • 165
robmathers
  • 3,028
  • 1
  • 26
  • 29
2

Swift 5

NSWorkspace.shared.openFile(YOUR_PATH)
Ahmadreza
  • 6,950
  • 5
  • 50
  • 69