I have a macOS app which most users use by drag and dropping images on the app icon or my menu bar icon. Some users also use my app through Terminal by running the following commands:
open -a /Users/username/Library/Developer/Xcode/DerivedData/AppName-bomyuotvsgqtachwwiidvpiaktgc/Build/Products/Debug/AppName.app /Users/username/Downloads/image.jpeg
My app handles the link/links being passed in the func application(_ sender: NSApplication, openFiles filenames: [String]) method of AppDelegate.
This works fine so far. If my app is already open, the openFiles still gets called by MacOS with the new image path and my app opens a new window to display it. This all works well.
Now I want users to be able to pass certain arguments to my app. For example this:
open -a /Users/username/Library/Developer/Xcode/DerivedData/AppName-bomyuotvsgqtachwwiidvpiaktgc/Build/Products/Debug/AppName.app /Users/username/Downloads/image.jpeg --args full
Here I want to receive the full argument. I read on few other posts to use the CommandLine.arguments API. But this doesn't seem to contain the arguments. Each time the value of CommandLine.arguments equals to this:
["/Users/username/Library/Developer/Xcode/DerivedData/AppName-bomyuotvsgqtachwwiidvpiaktgc/Build/Products/Debug/AppName.app/Contents/MacOS/AppName", "-NSDocumentRevisionsDebugMode", "YES"]
I think this is because the CommandLine.arguments only works when the app is initially launched and arguments are passed into the main function. But for an already opened app, these don't get passed as main isn't called again for an already running app.
How do I achieve this?
