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
.
NSDistributedNotificationCenter
would likely work fine, if that is the abstraction level you prefer. Its interfaces are similar to NSNotificationCenter
. Regarding NSDistributedNotificationCenter
:
userInfo:
parameterYou may find sockets preferable if you want to transfer a lot of information, or if you want something more robust/predictable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With