Uninstall an AppleScript application from within Itself

Dec 09, '09 07:30:01AM

Contributed by: Andrew J Freyer

If you make tiny apps that you distribute to friends and family who aren't particularly Mac-literate, you might find this snippet of code helpful:

set theUNIXPath to path to me as alias
set thePosixPath to (POSIX path of theUNIXPath) as string
set thePosixPath to (items 1 thru ((length of thePosixPath) - 1) of thePosixPath)
		
do shell script "sleep 1 &> /dev/null &
mv " & thePosixPath & " ~/.trash/YOURAPPNAMEGOESHERE.app"
return
Basically, any app with that code inserted (and properly activated based on response to a user's action) moves itself to the trash.

How it works: it calls sleep 1 with a bash redirection command &> /dev/null &, which initiates the script, but returns to the app immediately. The effect is that your AppleScript app will exit before the second command moves the app to the trash.

Comments (16)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20091126091003749