macOS, call uninstall script when drag-and-drop app into the trash icon

I'm working on some app that has LaunchDaemon running on the background, and thus it requires some operations to be removed, prior to deleting the data/exe files.

Is there an option to call an uninstall script upon drag-and-drop my app into the trash bin ? or at least, prevent the uninstallation and trigger popup window that tells the user this app cannot be removed until he unload the service (sudo launchctl stop /Library/LaunchDaemons... or sudo launchctl unload -w /Library/LaunchDaemons...)

my app uses pkg file format for deployment, but I couldn't find any uninstall callback within this format. is there a way to do so ? Thanks

Is there an option to call an uninstall script upon drag-and-drop my app into the trash bin?

No.

prevent the uninstallation and trigger popup window that tells the user this app cannot be removed until he unload the service

I’m not sure. We support this for apps containing system extensions but, historically, we’ve never supported it for apps containing daemons [1]. However, in macOS 13 we added SMAppService, which lets you install a daemon embedded within your app. I haven’t yet tested whether we apply the existing sysex smarts to this when it comes to app removal. It’s worth testing out though.

Share and Enjoy

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

[1] Which makes sense because, historically, running a daemon directly from within your app was a really bad idea.

macOS, call uninstall script when drag-and-drop app into the trash icon
 
 
Q