views:

576

answers:

2

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?

+2  A: 

This book is probably the best published resource for doing a CLI application on Mac OS X.

Alex Reynolds
Clinton Blackmore
+5  A: 

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.

Naaff
Thanks, that link looks like it'll be a good intro to building multiple targets. I also like the idea of accepting the arguments directly, but I agree that it also sounds a little messy.
Lawrence Johnston