2

here is the situation:

Current situation

I have an NSDocument application (macOS), which works currently only via the Graphical User Interface (GUI). The app is written in Swift 4.

Wished situation

I would like to offer a Commande-Line Interface (CLI) for the app which would take the NSDocument file (a config file actually) as argument. The NSDocument is needed to access the data (stored using Core Data) inside. When using the app via command-line, the GUI should not be started. The use is either via the GUI, or via the CLI.

What I already know

I think that I should rewrite @NSApplicationMain to be able to retrieve the app arguments, but I could not find any concrete example in Swift.


Has someone already done something similar and could give me a hint of how to achieve this, in Swift ? Thanks a lot in advance !

vomi
  • 993
  • 8
  • 18
  • Possible duplicate of [Cocoa: Pass arguments to NSApplicationDelegate](https://stackoverflow.com/questions/5616959/cocoa-pass-arguments-to-nsapplicationdelegate) – Willeke Dec 08 '17 at 23:04
  • Sorry but no, it does not explain how to get around ``@NSApplicationMain``, it is in Objective-C, and it just explains how to basically get the arguments of the app. – vomi Dec 09 '17 at 12:04
  • It's `ProcessInfo.processInfo.arguments` in Swift. You can open the document with `openDocument(withContentsOf:display:completionHandler:)` of `NSDocumentController` and terminate the app in the completion handler. – Willeke Dec 09 '17 at 15:36
  • The other solution is a command line tool and a GUI wrapper. – Willeke Dec 09 '17 at 15:41

0 Answers0