Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Make an AppleScript Studio application self-update System
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:

  1. 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
  2. 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."
  3. 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.
    •    
  • Currently 2.20 / 5
  You rated: 4 / 5 (5 votes cast)
 
[6,615 views]  

Make an AppleScript Studio application self-update | 9 comments | Create New Account
Click here to return to the 'Make an AppleScript Studio application self-update' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Make an AppleScript Studio application self-update
Authored by: Chris Biagini on Apr 06, '05 10:11:34AM
You might want to use
path to temporary items
instead, so you're not mucking around at the root of the hard drive.

[ Reply to This | # ]
Make an AppleScript Studio application self-update
Authored by: sjmills on Apr 06, '05 12:23:00PM
Comparing version strings won't always work if your version numbers include bug fix numbers (the 3rd number in "a.b.c"). One example of where comparing version strings fails is:
return "1.0.10" < "1.0.2"
 -->true
But in that case, "10" is not a "normal" bug fix number, since it exceeds the 0-9 range. To compare versions correctly, you need to convert them into BCD (binary-coded decimal) or compare the version parts individually, e.g.:

on CompareVersions(v1, v2)
	--v1 and v2 are version strings in either "a.b" or "a.b.c" form.
	--Return true if v1 < v2.
	
	set sd to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {"."}
	
	set maj1 to text item 1 of v1 as number
	set min1 to text item 2 of v1 as number
	
	try
		set bug1 to text item 3 of v1 as number
	on error
		set bug1 to 0
	end try
	
	set maj2 to text item 1 of v2 as number
	set min2 to text item 2 of v2 as number
	
	try
		set bug2 to text item 3 of v2 as number
	on error
		set bug2 to 0
	end try
	
	set AppleScript's text item delimiters to sd
	
	return maj1 < maj2 or (maj1 = maj2 and (min1 < min2 or (min1 = min2 and bug1 < bug2)))
end CompareVersions
Of course, this doesn't handle the case where you have letters and build numbers at the end, like 1.0.2b14.

[ Reply to This | # ]
Make an AppleScript Studio application self-update
Authored by: sjmills on Apr 06, '05 12:26:23PM

Actually, "10.0 < 2.0" also fails, and 10.0 is a completely valid version number.



[ Reply to This | # ]
Make an AppleScript Studio application self-update
Authored by: geowar1 on Sep 15, '11 04:00:27PM

Mac OS X 10.4 added "considering numeric strings" so that version strings will compare correctly ("10.6.2" < "10.6.10").

on CompareVersionStrings(v1, v2)
considering numeric strings
set isLess to (v1 < v2)
end considering numeric strings
return isLess
end -- on CompareVersionStrings



[ Reply to This | # ]
Make an AppleScript Studio application self-update
Authored by: nicorohrbach on Apr 06, '05 02:25:27PM

It's much easyer to get the current version number from the online text file with curl. just write 1.0 to the online text file instead of CurrentVersion=1.0 and use do shell script to run curl and get the text:

set UpdateVersion to do shell script "curl http://yoursite.edu/CurrentVersion.txt"

[ Reply to This | # ]
Yes, but "curl" does not honor the proxy setting...
Authored by: aamann on Apr 06, '05 09:33:37PM

The problem with using curl for this is that it will go directly to port 80 in your example - if you use a proxy server, this will be ignored and curl might not be able to connect properly. The "URL Scripting Access" honors the system's proxy settings and thus indeed is the better choice!



[ Reply to This | # ]
Yes, but "curl" does not honor the proxy setting...
Authored by: gvaughn on Apr 07, '05 10:22:49AM

That is correct, but curl does have a .curlrc (I think that's the name) where the proxy server can be specified. One of the things on my to-do list is to figure out a way to automatically synchronize that with the system proxy setting. Has anyone tackled that yet?



[ Reply to This | # ]
Yes, but "curl" does not honor the proxy setting...
Authored by: aamann on Apr 07, '05 12:17:49PM
I looked at this (getting the system's proxy settings based on the current location) but decided against it - it would have been too painful to do so (at least much more painful than using three lines with URL Access Scripting instead...)

Take a look at this thread in the Apple Discussions

[ Reply to This | # ]
Yes, but "curl" does not honor the proxy setting...
Authored by: gvaughn on Apr 07, '05 06:18:36PM

Thanks for that reference. It is harder than I thought. Unfortunately, I do have to deal with authenticating proxies. I've done that successfully with wget on a Linux box, but I'm not sure about curl. I had a bad experience with URL Access Scripting on OS 9.



[ Reply to This | # ]