• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Comparing version strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comparing version strings


  • Subject: Re: Comparing version strings
  • From: Christopher Nebel <email@hidden>
  • Date: Thu, 11 Dec 2008 12:09:08 -0800

On Dec 11, 2008, at 8:18 AM, Luther Fuller wrote:

On Dec 11, 2008, at 8:05 AM, SVV Satyanarayana wrote:

The following command give the version of mono:
do shell script "/usr/bin/mono -V | awk '/version/ {print $5}'"

I am getting the output as "1.2.5"
Now I want to compare the mono version whether it is greater than or equal to 1.2.5 using script.
How to check it through Apple Script.

Here's what I use ...

set AppleScript's text item delimiters to {"."}
(text items of (system version of (system info)) & {"0", "0", "0"})
1000000 * (item 1 of the result) + 1000 * (item 2 of the result) + (item 3 of the result)
if the result < 10005000 then
-- do stuff for Tiger only
end if

If you can be sure that each component is always exactly one digit, then you can just do a normal string comparison. The difficulty is if they're not -- for instance, "1.3" should be less than "1.10", but isn't in a straight lexicographical compare. To get around this, you can use some clever manipulation like Mr. Fuller describes, or, if you can assume you're using Tiger (10.4) or later, you can use the AppleScript feature that's designed for exactly this:


	"1.2" < "1.2.5" --> true
	"1.3" < "1.2.5" --> false
	"1.3" < "1.10" --> false; oops.
	considering numeric strings
		"1.3" < "1.10" --> true; better.
	end

--Chris Nebel
AppleScript Engineering
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >Finder folder names (From: Luther Fuller <email@hidden>)
 >Re: Finder folder names (From: Luther Fuller <email@hidden>)
 >Re: Finder folder names (From: Tim Mansour <email@hidden>)
 >Re: Finder folder names (From: Luther Fuller <email@hidden>)
 >Dock folder menus (From: Luther Fuller <email@hidden>)
 >Comparing version strings (From: SVV Satyanarayana <email@hidden>)
 >Re: Comparing version strings (From: Luther Fuller <email@hidden>)

  • Prev by Date: Re: Code Signing
  • Next by Date: Code Signing.
  • Previous by thread: Re: Comparing version strings
  • Next by thread: Re: Comparing version strings
  • Index(es):
    • Date
    • Thread