Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gpchess2k

macrumors member
Original poster
Oct 12, 2015
42
0
Hello, everyone! Im trying to do a simple script where it pulls the version number of an app and checks to see if its less than. I dumbed down the script down below. AppleScript only looks at the first number after the decimal place to determine what's greater. In the example below, 4.17.9 is greater than 4.17.10.

Code:
tell application "System Events"
    set driverVersion to "4.17.9"
    if driverVersion < "4.17.10" then
        display dialog "OLDER"
    else
        display dialog "NEWER!"
    end if
end tell
 

Senor Cuete

macrumors 6502
Nov 9, 2011
429
31
Not AppleScript but...
Code:
BOOL runningOnAtleast(int majorVersion, int minorVersion, int patchVersion)
{
    NSOperatingSystemVersion OSVersion; //struct with three variables declared as NSIntegers:
    OSVersion.majorVersion = majorVersion;
    OSVersion.minorVersion = minorVersion;
    OSVersion.patchVersion = patchVersion;
    return [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion: OSVersion];
}
 

gpchess2k

macrumors member
Original poster
Oct 12, 2015
42
0
Thanks for the response but I do need a solution for AppleScript specifically.
 

Red Menace

macrumors 6502a
May 29, 2011
583
230
Colorado, USA
Normally strings are compared according to their character values, but for comparing them numerically you can use a considering statement, for example:

AppleScript:
set driverVersion to "4.17.9"
considering numeric strings
    if driverVersion < "4.17.10" then
        display dialog "OLDER"
    else
        display dialog "NEWER!"
    end if
end considering
 
  • Like
Reactions: NoBoMac and chown33

gpchess2k

macrumors member
Original poster
Oct 12, 2015
42
0
That worked perfectly! I dont know how I missed this in the documentation and googling around. Appreciate it greatly!!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.