Here's a pair of handlers to include in an AppleScript Studio project to have an application update itself. The first handler creates a folder called "TempFolder" at the root of the startup disk, so we have a consistent space to play around with. The second actually does the backup check. The
CheckForUpdate() handler was written by David Klawiter, a colleague of mine.
Here's what you have to do:
- Create a text file and save it in your web space (represented by the variable target_URL). The contents of the text file should be: CurrentVersion=1.0
- In your XCode project, be sure to provide a version number by double-clicking the target application, then typing in the version number into the 'Info.plist Entries' sections called "Basic information" and "Display Information."
- Upload your new application to your web space in HQX format. (Obviously, you can make it any format you want, but this code assumes you have HQX'd it.)
When invoked, the handler compares the current application's version number (as given in step two above) to the current version you tell it (in the text file on the web, as given in setp one above). If the version number on the web is greater than the version number of the installed application, the current application moves itself to the temporary folder, downloads the new version of the application, sets the correct permissions, launches the new application, and quits itself.
We call these two handlers on
launch(), and we delete the entire TempFolder as part of a cleanup routine.