Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GUI-less App Bundle

I would like to create a helper application that has no GUI yet does have access to an app bundle. I was looking at the Xcode command line project templates, but these all just generate executable files. How can I create something like a command line tool that presents no application menu yet provides access to bundle resources in a .app? Am I thinking about this the wrong way?

Thanks.

like image 546
Matt Long Avatar asked Feb 09 '10 04:02

Matt Long


2 Answers

Peter's answer (use LSUIElement) is probably what you're looking for. Occasionally, I've wanted to create an actual command-line app that also has an app bundle. In case other's come across the same scenario, here's what I've found...

The app bundle is not an executable. The true executable is buried inside: MyApp.app/Contents/MacOS/MyApp is the actual Mach-O executable for an app named MyApp. The standard Xcode templates link applications against AppKit.framework and have a main.m that defines the main() function for the executable that starts an NSApplication instance. You can put any executable in an app bundle, however, including a console-only app. Just replace the main() function in main.m in the application template with your console apps main() function and remove AppKit.framework from the app's linked frameworks.

If you want, you can replace main.m with a main.c that declares a main function if you want to avoid Objective-C entirely (though there's nothing necessarily Objective-C specific in main.m if you replace the contents of the main() function).

To run your application from the console, you have to specify the actual executable, not the app bundle, so you'd have to type MyApp.app/Contents/MacOS/MyApp at the command line. When I've used app bundles for console apps (to provide linked frameworks, resources, etc.), I often create a symlink to the executable and put the symlink in /usr/local/bin (or somewhere else on the path) during installation or first run.

like image 113
Barry Wark Avatar answered Oct 17 '22 03:10

Barry Wark


I would like to create a helper application that has no GUI yet does have … an app bundle.

That's called an agent, and you make one by making a regular application and setting its LSUIElement key to the string “1”.

like image 37
Peter Hosey Avatar answered Oct 17 '22 04:10

Peter Hosey