0

I have developed a macOS app which will allow the app to be launched if the user double-clicks on a file with my defined file extension. The file extension association was done inside the Info.plist file. I am able to double-click a file to launch my app successfully. However, I can't seem to find out how I can get the name of the file that was used to launch the app.

The file name does not seem to be stored as part of argv. In my app I would like to be able to get the name of the file, perform some initialization code, and then open the file in my app environment.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Kenny
  • 429
  • 6
  • 22

1 Answers1

4

Implement the NSApplicationDelegate method func application(_ sender: NSApplication, openFile filename: String) -> Bool or func application(_ sender: NSApplication, openFiles filenames: [String]). This is called when your app is asked to open a file (or launched for a file).

rmaddy
  • 314,917
  • 42
  • 532
  • 579