21

As a service to my users I would like to provide an uninstall script to completely remove all traces of my application on Mac OS X. The application is installed using a package rather than just being dragged into the Applications folder because it is a daemon-type app that also requires to run a script at installation to be launched.

My thinking is to include a file called uninstall.sh and place it into /Library/Application Support/com.<mycompany>.<myapplication>/ and refer to this from the application documentation. The purpose is basically to stop the daemon if running, unload and delete the corresponding plist as well as remove any application files. Does this sound reasonable or are there better methods to accomplish this?

Also I am wondering if it is good practice to also remove traces of the package using pkgutil --forget - if I don't do this, the next time the package is installed it shows up as being upgraded instead of installed. Any recommendations or pointers to best-practice information?

Is there no standard way of doing this on OS X?

villintehaspam
  • 7,990
  • 6
  • 38
  • 75
  • 4
    You shouldn´t use dots in folder names like this — if you take a look into your `/Library/Application Support/` folder, you´ll see that it´s common practice to simply use your Application´s name for that folder. – Asmus Mar 15 '11 at 19:55
  • @Asmus: Thanks, I'll change into using /Library/Application Support//. – villintehaspam Mar 21 '11 at 14:03

5 Answers5

17

There is no standard way of doing this on OS X. Yes, shocking, I know. Apple consistently warns everyone away from package installers (among other things by providing insufficient documentation for them). They then exclusively use package installers for their own standalone apps.... go figure.

Yes, you should include pkgutil --forget.

If your customers are comfortable with this kind of script, then your approach sounds fine. If they want a "double-click-on-it" then you should probably put the uninstaller in /Applications, but avoid that if you can.

If you have a GUI, Status Item, or Preference Panel, then it's nice to put a "Uninstall" button or menu item there rather than requiring them to go mess around with Terminal.

BTW, if you go looking for the Software Delivery Guide, it's been moved for a year or so now, while they "update" it.

Rob Napier
  • 250,948
  • 34
  • 393
  • 528
7

the inability to remove packages has bugged me for years, so i've written a tool to uninstall packages:

http://www.corecode.at/uninstallpkg/index.html

its a bit better than the shell scripts to do it floating around because it makes sure never to remove any files that are used by any other installed packages

user1259710
  • 839
  • 1
  • 9
  • 11
  • PKG Uninstaller shows an error when I try to remove packages from Logic Pro X's sounds library. It says it can't remove the packages because of the System Integrity Protection. – rraallvv Sep 09 '17 at 21:07
  • @rraallvv: 1.) stackoverflow is not a support channel for random apps please contact us directly with your feedback 2.) since 10.11 SIP (System Integrity Protection) blocks any app from modifying system files ... if you want to remove a package that has been installed into those protected locations you have to disable the System Integrity Protection (temporary or permanently) – user1259710 Sep 11 '17 at 11:59
  • @user1259710 I'm not sure what you mean, anyway, I was able to remove the packages with the commands in [this gist](https://gist.github.com/githubutilities/b5318d08a4b970d104f1) without disabling SIP. – rraallvv Sep 11 '17 at 23:04
  • @rraallvv: you can remove the package itself but not any files the package has installed if they are in SIP-protected folders like /System .... thats just impossible regardless of using UninstallPKG or using this (unsafe) gist – user1259710 Sep 13 '17 at 08:42
4

The way I solved this was to use Automator, create an application document and then add dialog and script actions. Finally save your Automator application document and you end up with a simple GUI application to run the uninstall.

Often the uninstall action requires administrator privileges - I solved this in Automator by running a shell script action that generates another shell script that can then by run in an applescript action as follows:

on run {input, parameters}
    do shell script "/tmp/uninstaller.sh" with administrator privileges
    return input
end run
petert
  • 6,552
  • 3
  • 34
  • 45
4

I have a similar application and came across the same issue. The approach I took was one that I have seen other applications use. Rather than simply distributing the .pkg installer, wrap it up in a .dmg file. The uninstall script can be included with the .pkg in the .dmg.

The uninstall script is then renamed to "uninstall.tool". The .tool extension allows users to run the script by double clicking, rather than having to run it from the command line.

Steg
  • 9,402
  • 3
  • 21
  • 17
1

Slightly unconventional, but aren't these all. I have Homebrew and cask installed. I was able to uninstall a .pkg with the following:

 brew cask uninstall --force <pkg_name>

ex. brew cask uninstall --force dockertools

buildmaestro
  • 958
  • 1
  • 13
  • 30
  • (1) This is assuming that `dockertoolbox` was installed via Homebrew and cask. (2) This question is for general Mac OS applications, not just `dockertoolbox`. The validity of your answer is questionable. – rayryeng Feb 18 '16 at 21:24
  • Surprisingly no, dockertoolbox was installed via osx's installer from a .pkg yet brew cask with the --force option was able to uninstall dockertoolbox. – buildmaestro Feb 19 '16 at 19:50
  • That's interesting, but still this question is applicable to general OSX packages. Your answer is only for a specific package. – rayryeng Feb 19 '16 at 19:51
  • This works with all osx packages (which the question asked). All I can tell you is that where the above accepted answers did not work, this one did. I can be voted down, but I'm just sharing what worked for every osx package I tried. – buildmaestro Feb 25 '16 at 19:34
  • I didn't vote you down. That is also interesting. Thanks. In order to appease the downvote, you may want to reword your post so that it is worded for any general OSX package, not specifically to dockertoolbox. – rayryeng Feb 25 '16 at 19:52