function stsReadFromPlist pFile,pKeyPath
if there is a file pFile then
put url ("file:" & pFile) into tData
set the itemDel to "/"
repeat for each item tItem in pKeyPath
put offset("" & tItem & "",tData) into tOffset
if tOffset <> 0 then
delete char 1 to (tOffset + length("" & tItem & "")) of tData
else
return "STSError: Key not found at path '" & pKeyPath & "'"
end if
end repeat
-- remove preceding chars
repeat
if char 1 of tData = "<" then exit repeat
delete char 1 of tData
end repeat
if char 1 to 7 of tData ="" then
-- return an array
if matchText(tData,"(?si)(.*?)<\/array>",tElements) then
put "" into tRetValA
put 0 into tKeyNum
repeat
add 1 to tKeyNum
get matchText(tElements,"(?si)<.*?>(.*?)<\/.*?>",tVal)
if it is false then exit repeat
else
put tVal into tRetValA[tKeyNum]
get matchChunk(tElements,"(?si)(<.*?>(.*?)<\/.*?>)",tStart,tEnd)
delete char 1 to tEnd of tElements
end if
end repeat
return tRetValA
else
return "STSError: Could not extract array from key path '" & pKeyPath & "'"
end if
else
-- look for (like - this is used in loginwindow.plist)
if matchText(tData,"(?si)<(.*?)\/>",tVal) then
return tVal
else
-- look for Val, Val, etc.
if matchText(tData,"(?si)<.*?>(.*?)<\/.*?>",tVal) then
return tVal
end if
end if
return "STSError: Could not extract value from key path '" & pKeyPath & "'"
end if
else
return "STSError: FIle not found."
end if
end stsReadFromPlist