I’m in the process of updating iBabel and one of the things I’m adding is the option to use some of the newer tools now available in the latest version of OpenBabel. However some users prefer not to live on the bleeding edge and want to continue to use the older version of OpenBabel so I’d like to only have the tool options available for which ever version of OpenBabel they have installed.
You can get the version number of the OpenBabel installation with the simple command
1 2 3 |
/usr/local/bin/babel -V Open Babel 2.1.0 -- Apr 13 2007 -- 21:38:32 |
We can wrap this in an Applescript and use the “do shell script” command to get the returned text, simple parsing of the returned text then gives the version number.
set the_script to “/usr/local/bin/babel -V”
set theversion to (do shell script thescript)
display dialog the_version
—Open Babel 2.1.1 — Apr 13 2007 — 21:38:32
set theoffsetminus to the offset of “–” in theversion set theoffsetel to the offset of “el” in theversion
set babelversion to (characters (theoffsetel + 3) thru (theoffsetminus – 2) of theversion) as text
display dialog babel_version
Comparing version numbers however is not so straightforward since the version number could be 2.10.3 or 2.3.10, fortunately Apple have kindly provided a simple means to compare this type of numeric strings. So using “considering numeric strings”.
considering numeric strings
if babel_version > “2.1” is true then —> true, if you consider each numeric string to be a single “character”.
display dialog “True”
end
if
end considering
The actual implementation in iBabel is this:-
considering numeric strings
–Different tools available depending on version of iBabel
if babelversion > “2.1” is true then –> true, if you consider each numeric string to be a single “character”. –display dialog “2.2”
repeat with i in my toolsOptionsNew
make new menu item at the end of menu items of menu of popup button “toolsOption” of tab view item “Tools” of tab view “nstab” with properties {title:i, enabled:true}
end repeat
else if babelversion < “2.1” is true then
–display dialog “2.0”
repeat with i in my toolsOptionsOld
make new menu item at the end of menu items of menu of popup button “toolsOption” of tab view item “Tools” of tab view “nstab” with properties {title:i, enabled:true}
end repeat
end if
end considering
So depending on the version of OpenBabel I load a different list of tools options.