Creating bundled background application in macOS

I wanted to create a bundled macOS application that can be run in background. This application should also be capable of running in a non-gui environment.

How should I create the application with the only condition that it should be bundled and can be launched using multiple ways like double click the bundle app or launching as a daemon using the unix executable?

This seems like a followup questions from your earlier thread, where Kevin is addressing very similar points.

My general take on this is that you should not try to create a single executable that runs as both a GUI app and a daemon. There’s no good way to do that because:

  • The GUI app must necessarily link to AppKit (or SwiftUI, which links with AppKit internally).

  • A daemon cannot link with AppKit, because it’s not a daemon-safe framework per Technote 2083 Daemons and Agents.

A better option is to have multiple executables, one for each context. If you want to share code between them, put that code in a framework.

IMPORTANT Because that framework will be loaded into a daemon, it’s must only use daemon-safe frameworks.


Based on this and the other threads you’ve been starting recently, it’s clear that you really need to read and fully understand TN2083. The rules described in that technote will help you create an architecture that works today and in the future. If you don’t follow them carefully, you’ll continue to run problems. If you’re lucky, you’ll find those problems during development. If not, you may only find those problems during deployment, or as macOS evolves over time.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Creating bundled background application in macOS
 
 
Q