Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a command line frontend for a GUI Cocoa app?

I'm creating a mainly GUI Cocoa app, but I want to create a command line front end as well that prints the same data so I can display it using geektool.

I'm guessing I need to create an additional command line custom executable in my Xcode project and build it alongside the GUI executable? Is there a tutorial around for how to do this?

like image 963
Lawrence Johnston Avatar asked Dec 30 '22 00:12

Lawrence Johnston


1 Answers

You can use XCode to build multiple targets. As you suggested, just make your second target a command line tool (just pick the appropriate option under "Command Line Utility" in the New Project assistant when you create your new target).

Edit: It's also possible embed your command line tool inside your app or even have one executable do both jobs. Embedding your command line app might be interesting if you'd like to be able to distribute your app and have it come with your (separate) command line tool.

To have one executable do both jobs you'd have to accept command line arguments in main (usually main.m is generate for you by XCode). However, this can get messy so it's probably better to just have a seperate front end.

like image 189
Naaff Avatar answered Jan 13 '23 13:01

Naaff