macosuser-interfacekernelrootuninstallation

OS X kernel extension graphical uninstaller


XCode doesn't include uninstallation options for their packager. Generally users simply drag the app to the trash if they want to uninstall it - most apps are self contained in the app package.

However, I have a kernel extension which must be uninstalled using a few simple command lines. There is a script that works, but I am required to provide a graphical uninstaller.

I don't expect there's a plug-n-play example code out there that provides a way to run the script while showing a progress bar, but I'm hoping someone has dealt with this or has a few pointers on how to accomplish this quickly and easily

The script is only two lines with no feedback, so we can execute the commands in the app, as long as we can easily request and use root permissions securely (ie, let OS X handle the permissions - we merely ask for OS X to give them to us which should cause it to ask the user for them similar to how it happens with the package installer) inside the app.


Solution

  • There's a reasonably good approach using a Cocoa-Applescript project in xcode to run a shell script here:

    http://www.mactech.com/articles/mactech/Vol.22/22.08/GUI-upyourScript/index.html

    It covers using a progress bar, handling errors, and getting the correct root permissions to run the shell script.

    Unfortunately it's a bit long to cut and paste here, but the general steps are:

    1. Create new xcode project of type Cocoa-Applescript app
    2. Create and test the intended shell script, add it to your project
    3. Edit the MainMenu.nib to add and name a button(theObject) and progress bar(pMainProgress), then edit title and other aspects of the ui to taste
    4. Tie the button to the applescript in the project (in the Inspector with the button selected check the action box and put in myprojectname.applescript)
    5. Edit the applescript to something akin to the following:
    on clicked theObject
       -- setup
       set myPath to POSIX path of (path to me) as string
       -- Start progress bar
       set uses threaded animation of progress indicator "pMainProgress" of window "wMain" to true
       tell progress indicator "pMainProgress" of window "wMain" to start
    
       -- Do it!
       try
          do shell script quoted form of myPath & "Contents/Resources/backup.sh" with administrator privileges
       on error number 255
          display dialog "Sorry, an error occurred.  I can't make the copy."
       end try
       -- Stop progress bar
       tell progress indicator "pMainProgress" of window "wMain" to stop
       set uses threaded animation of progress indicator "pMainProgress" of window "wMain" to false
    
    end clicked
    

    You can further customize the app (name, for instance) and add text boxes to the window to alert the user what step is happening if you're running multiple scripts (put set the contents of text field "efStatus" of window "wMain" to "Copying files..." in your script after adding a text field to the ui with the name "efStatus")