Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uninstaller for a cocoa application

I am using PackageMaker for the installer of my application (which is more than a simple bundle). I am wondering how to create an uninstaller, where to install it and how to provide to the user a way to launch it.

Thanks in advance for your help,

like image 740
AP. Avatar asked Dec 10 '22 12:12

AP.


1 Answers

While implementing an uninstaller for some MAC OS application, we've come up with an idea. As SerpicoLugNut says:

Seriously - 98% of Mac apps don't offer an uninstaller, and if most people want the app uninstalled, they will just drag the app to the trash

We deviced that we can watch the Trash, and in case our application appears in the Trash, we can ask a user if he/she wants to uninstall it.

Fortunately, the MAC OS provides an out-of-box functionality to implement this. You just have to put the following .plist to the /Library/LaunchAgents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.your.app</string>
<key>WatchPaths</key>
<array>
    <string>~/.Trash</string>
</array>
<key>ProgramArguments</key>
<array>
    <string>osascript</string>
    <string>/path/to/your/app/Check Trash.applescript</string>
</array>
<key>KeepAlive</key>
<false/>

In this example, a Check Trash.applescript is run once the user's Trash is modified. This script should check that your application is in the Trash and ask the user if he/she wants to proceed with the uninstall. Of course this can be an arbitrary script or even a binary executable, not only an applescript. For more information, look at the man page for launchd.plist

like image 121
Oleg Yakovenko Avatar answered Dec 27 '22 00:12

Oleg Yakovenko