Platforms to show: All Mac Windows Linux Cross-Platform

FAQ.How to get the version information for a Mac OS application?
Feedback.

Answer:
Complete Question:
I'm trying to get a variety of information about a folderItem - size, modification date, creation date, etc. I've used MBS to get things like kind and label, but the one thing I can't seem to get is version for any folderitem that is an application (or bundle). Is there a function to get this in MBS?
Example:
Sub Open()
dim f as FolderItem

f=GetFolderItem("REALbasic 5.5.5 Mac OS X.app")

StaticText1.text= GetVersion(f)

f=GetFolderItem("REALbasic 4.5.3 Classic")

StaticText2.text= getversion(f)
End Sub

Protected Function GetVersion(f as folderitem) As string
if f.Directory then
Return GetBundleVersion(f)
else
Return GetResourceVersion(f)
end if
End Function

Protected Function GetResourceVersion(f as folderitem) As string
dim r as ResourceFork
dim s as string
dim b7 as string
dim l as integer

r=f.OpenResourceFork
s=r.GetResource("vers",1) // read vers resource

b7=midb(s,7,1) // get byte 7
l=asc(b7)

s=midb(s,8,l) // copy bytes

Return ConvertEncoding(s,Encodings.MacRoman)

Exception
End Function

Protected Function GetBundleVersion(f as folderitem) As string
dim b as CFBundleMBS
dim u as CFURLMBS
dim o as CFObjectMBS
dim s as CFStringMBS

u=NewCFURLMBSFile(f) // make a CFURL

b=CreateBundleMBS(u) // so we can open the bundle

// now copy the version value
o=b.GetValueForInfoDictionaryKey(b.kCFBundleVersionKey)

// should be a CFString
s=CFStringMBS(o)

// make a RB string
Return s.str

Exception

End Function

Notes: The code above does this. You may modify it for your needs, but it returns "RB 4.5.3" for the old classic RB and "5.5.5" for the new version.



Links
MBS Realbasic tutorial videos - Pfarrgemeinde Messdiener Nickenich