Platforms to show: All Mac Windows Linux Cross-Platform

/MacOSX/Plist Parsing
Feedback.

Function:
You find this example project in your Plugins Download as a Realbasic project file within the examples folder: /MacOSX/Plist Parsing
This example is the version from Tue, 16th May 2005.
Notes: Last modified: Tue, 16th May 2005
Class Window1
Inherits Window
// Controls
ControlInstance
End ControlInstance

// Event implementations
Sub Deactivate()

End Sub
Sub Open()
dim f as FolderItem
dim b as BinaryStream
dim s as string
dim co as CFObjectMBS
dim cb as CFBinaryDataMBS
dim cd as CFDictionaryMBS
dim ca as CFArrayMBS
dim i,c as integer
dim extension as string
dim iconfile as string
dim name as string
dim role as string
dim OStypes as string

if not RunningOnCarbonXMBS then
MsgBox "This example is only for Mac OS X!"
end if

f=ApplicationsFolderMBS(-32767)
f=f.Child("textedit.app")
f=f.Child("Contents")
f=f.Child("Info.plist")

b=f.OpenAsBinaryFile(false)
s=b.Read(b.Length)

cb=NewCFBinaryDataMBSStr(s)
co=NewCFObjectMBSFromXML(cb)

cd=CFDictionaryMBS(co) // it's a dictionary as seen on the console

// get subdictionary
co=cd.Value(NewCFStringMBS("CFBundleDocumentTypes"))
ca=CFArrayMBS(co)

c=ca.Count-1

for i=0 to c
co=ca.Item(i)
cd=CFDictionaryMBS(co)

Extension=MakeString(cd.Value(NewCFStringMBS("CFBundleTypeExtensions")))
iconfile=MakeString(cd.Value(NewCFStringMBS("CFBundleTypeIconFile")))
name=MakeString(cd.Value(NewCFStringMBS("CFBundleTypeName")))
role=MakeString(cd.Value(NewCFStringMBS("CFBundleTypeRole")))
OStypes=MakeString(cd.Value(NewCFStringMBS("CFBundleTypeOSTypes")))

List.AddRow Extension
List.cell(List.LastIndex,1)=iconfile
List.cell(List.LastIndex,2)=name
List.cell(List.LastIndex,3)=role
List.cell(List.LastIndex,4)=OStypes

next
End Sub

// Methods
Function MakeString(o as cfobjectMBS) As string
dim i,c as integer
dim ca as CFArrayMBS
dim cs as CFStringMBS
dim s as string

if o<>Nil then

if o isa CFStringMBS then
cs=CFStringMBS(o)
if cs<>nil then
Return cs.str
end if
end if

if o isa CFArrayMBS then

ca=CFArrayMBS(o)
if ca<>nil then
c=ca.Count-1
s=MakeString(ca.Item(0))
for i=1 to c
s=s+", "+MakeString(ca.Item(i))
next
end if
end if

Return s
end if

End Function
End Class

Class App
Inherits Application
End Class





Links
MBS Realbasic PDF Plugins - Pfarrgemeinde St. Arnulf Nickenich