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

330 views Asked by At

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 ?

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

1

There are 1 answers

0
pmdj On

This has been asked previously and in short, there hasn't been a good way of doing this up to and including macOS 12 'Monterey'.

However, there have been some changes in this area with macOS 13.0 Ventura; there's an introduction to the new mechanism in the WWDC22 session 'What’s new in privacy'. The new SMAppService APIs support automatic cleanup. Unfortunately you'll of course still have to find a workaround for any older macOS versions you support.

One way to ensure you don't consume unnecessary resources on a user's system, especially if uninstall isn't clean and the user isn't expecting your code to be lying around on their system anymore, is to avoid launching your daemon on every boot. Try to make it launch conditionally based on events, such as when your app first tries to connect via XPC/Mach, or using IOKit XPC events when the user first plugs in the device your daemon is driving.