GUI-less App Bundle

前端 未结 2 1793
悲哀的现实
悲哀的现实 2021-02-06 03:28

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

相关标签:
2条回答
  • 2021-02-06 04:06

    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.

    0 讨论(0)
  • 2021-02-06 04:24

    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”.

    0 讨论(0)
提交回复
热议问题