DEVONThink uses a quasi-numerical string as it’s version string which is retreived by the version class in AppleScript.
It’s not easy to do version checking, and a German user alerted me to a problem. My guess is that on international systems, you can’t make “1.1” into a number, it has to be “1,1”.
So the script I was using fails:
property minvers : "1.1.2"
tell application "DEVONthink Pro"
set versionok to true
set thevers to version as string
if (characters 1 thru 3 of thevers) as string as number is less than (characters 1 thru 3 of minvers) as string as number then
set versionok to false
else if (characters 1 thru 3 of thevers) as string is (characters 1 thru 3 of minvers) as string then
try
if character 4 of thevers is "." and ((character 5 of thevers) as number < (character 5 of minvers) as number) then
set versionok to false
end if
end try
end if
end tell
set result to {versionok, thevers}
I suppose I could try to make “1.1” into a number and on error search all “.” replacing with “,”. Would that solve the problem?
Is there any more elegant way to deal with the fact that you have:
a) international systems where “.” can’t be coerced into a number.
b) version strings that can be:
1.1
1.1.1
1.1.1beta1
etc
ok, so this is some code that should work. not very elegant though.
edit 1: what i first posted won’t work, I realized. I think this should. Code has been updated.
property minvers : "1.1.2"
global versionok, thevers
my version_check()
set result to {versionok, thevers}
on version_check()
tell application "DEVONthink Pro"
set versionok to true
set thevers to version as string
set thedecimal to "."
try
set base_vers to (characters 1 thru 3 of thevers) as string as number
set base_min to (characters 1 thru 3 of minvers) as string as number
on error
set thedecimal to ","
set thevers to my replace(thevers, ".", thedecimal)
set base_vers to (characters 1 thru 3 of thevers) as string as number
set base_min to (characters 1 thru 3 of minvers) as string
set base_min to my replace(base_min, ".", thedecimal)
end try
if base_vers is less than base_min then
set versionok to false
else if base_vers is base_min then
try
if character 4 of thevers is thedecimal and ((character 5 of thevers) as number < (character 5 of minvers) as number) then
set versionok to false
end if
end try
end if
end tell
end version_check
on replace(source, search, replacement)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to the search
set the textItemList to every text item of the source
set AppleScript's text item delimiters to the replacement
set the output to the textItemList as string
set AppleScript's text item delimiters to oldDelim
return output
end replace
I had to solve this problem for an earlier script I wrote, and did it by writing a sub routine that converted all version numbers to a digit number that should be comparable with a simple string call. The log commands here can be deleted, they just show that it works properly, even with double digit “points”…
erico
---eric oberle's version checking routine
property minvers : "1.1.2"
log my create_base_10_version("1")
log my create_base_10_version("1.1")
log my create_base_10_version("1.1beta")
log my create_base_10_version("1.1.2")
log my create_base_10_version("1.3.4beta")
log my create_base_10_version("1.3.4.2")
log my create_base_10_version("1.12")
log my create_base_10_version("1.2.1")
log my create_base_10_version("2,0")
log my create_base_10_version("12,0")
tell application "DEVONthink Pro"
set versionok to true
set thevers to version as string
if my create_base_10_version(thevers) is less than my create_base_10_version(minvers) then
display dialog "this version does not meet the minimum requirements"
set versionok to false
end if
end tell
on create_base_10_version(version_string)
set pad_number to 9
set oldDelim to AppleScript's text item delimiters
set sys_delimiter to "."
if version_string contains "," then set sys_delimiter to ","
set AppleScript's text item delimiters to sys_delimiter
set digit_list to every text item in version_string
set base_10 to 0
repeat with this_digit in digit_list
if this_digit contains "beta" then set this_digit to (characters 1 through ((offset of "beta" in this_digit) - 1) of this_digit) as string
set base_10 to (base_10 as number) * 100 + this_digit
end repeat
set base_10 to base_10 * (10 ^ (pad_number - (length of (base_10 as string))))
if ((first item in digit_list as number) >= 10) then set base_10 to ("1" & base_10 as string)
set AppleScript's text item delimiters to oldDelim
return (base_10 as number)
end create_base_10_version
erico, thanks. that’s really sleek. only one question though. do you have access to a system that uses “,”? Because I am having some trouble testing this.
In your routine, it assumes that the version string on an international system already contains “,” as in “1,1,1”. However, I do not think it does, that is I think the string is already “1.1.1”.
But I also now see the nice thing is that your code doesn’t rely on coecion of a decimal string into a number at all. So actually I think it would work whether or not the version string for DTP contains “,” or “.”
The only problem I notice is that it seems limited to 9 versions of DTP! Version 10 would be incorrect because the first digit is not padded on that end.
I think this should work with any system. I changed my prefs in the system control panel to europe, and it didn’t change the version string. I assume it never will, but just in case, if I see a comma in it, I use commas for evaluating the string…
Just for good luck (may devonthink make it to version 99!), I modified the code above so its good up to version 100!
now that’s what i call forward-looking. but why only 99? of course AppleScript won’t exist anymore after version 100 of DTP, but then neither will base ten systems, or for that matter “thinking” as such. But DTP, as we know, will become the core logic of the biosynthetic network whose true reach and scope only the Flying Spaghetti Monster fully grasps.
btw erico, did you get my e-mail messages re: NYT?