I was in need for a way to determine it the installed version of java was at a minimum level. The hardest part was coming up with the line of code that actually put the version of java into a variable just the way I needed it. After that was accomplished I was able to compare this number to a “minimum version” number I determined. If the version was too low, I had the script run the Java updater I downloaded from Apple.
If anyone knows of a more “Apple Script” way to do this I would be greatly appreciative. While I don’t mind using the do shell script function, I can’t help but to think that there is a better way to accomplish this task.
Hope this helps,
Jason Gutierrez
OS version: OS X
set javaver to (do shell script "java -version 2>&1 | grep 'java version' 2>&1 | awk '{print $3}' | sed 's/\"//g'") -- a complicated way of obtaining the version number of java and sticking it in a variable.
set minJava to "1.4.2" -- The minimum version of java.
try
if javaver < minJava then
display dialog "Your version of Java is: " & javaver & return & "You must update to version " & minJava & " or greater." & return & "Would you like to update you verion of Java now?" buttons {"Yes, update Java", "No, not at this time"} default button 1
copy the result as list to {the updateJava}
if updateJava is "Yes, update Java" then
do shell script "open /Volumes/diskimage/Java142Update1.pkg" -- modify this line to taste
end if
else
display dialog "Your version of Java is: " & javaver & return & "The required version is :" & minJava
end if
end try