Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command Line Tool interact with Cocoa app

I have a Cocoa Document-Based Application (text editor) and I want to be able to interact with it from the command line.

For example, I'd like to set it as the editor for typing git/svn commit messages on the command line.

Assuming I create a Command Line Tool using Foundation, what is the best way for my command line tool to communicate with the GUI application?

Obviously I can use standard open events to have my app open a specific file, but I also need the command line app to wait until the GUI app has finished with the document (user closes the editor window) before exiting (similar to mate -w file.txt in TextMate's command line tool, or the equivalent in various other mac text editors).

TextMate 2 uses a socket file. Is this the best approach? If possible I'd like to use something higher level, perhaps NSDistributedNotificationCenter.

like image 693
Abhi Beckert Avatar asked Oct 12 '12 05:10

Abhi Beckert


1 Answers

NSDistributedNotificationCenter would likely work fine, if that is the abstraction level you prefer. Its interfaces are similar to NSNotificationCenter. Regarding NSDistributedNotificationCenter:

  • it is limited to plist types
  • dropping notifications are permitted
  • it is 'expensive'
  • the latency may be unpredictable
  • Sandboxed apps cannot use the userInfo: parameter

You may find sockets preferable if you want to transfer a lot of information, or if you want something more robust/predictable.

like image 193
justin Avatar answered Oct 02 '22 19:10

justin