Hi all,
I am trying to parse the metadata for a folder and its entire contents to a plist file, and store the metadata as a value for a key that is the file/folders name. Using the fourm, and various other sources, I have almost gotten it working. I currently can parse an entire folder and its contents (function not shown), return that as a list of POSIX paths, which I then can grab the metadata for and return as a dictionary using getMetaDataDict().
My question is how I can then write that dictionary to the plist file. The ways I am seeing people write info to dictionaries in plist’s involves going item by item. I would like to avoid having to parse over the contents of the fileMetaDataDict because that would also mean detecting when the values are arrays/dicts and whatnot. Which I can do, but I would hope there is an easier way.
on getMetaDataDict(fileRef)
set fileAlias to fileRef as POSIX file as alias
set mdItem to current application's NSMetadataItem's alloc()'s initWithURL:fileAlias
set theMetadata to (mdItem's valuesForAttributes:(mdItem's attributes())) as record
set itemMetaDataDict to current application's NSDictionary's dictionaryWithDictionary:theMetadata
return itemMetaDataDict
end getMetaDataDict
on getMetaData(getMeta, outputLocation, shellPassword)
-- maybe PlistBuddy needs to get involved
if getMeta as boolean then
set fileLocation to outputLocation & "MetaData/"
do shell script "mkdir " & fileLocation
set scriptLocation to (current application's NSBundle's mainBundle()'s resourcePath() as text) & "/subScripts/getEverything.scpt"
set getEverything to load script current application's POSIX file scriptLocation
tell getEverything
set allContents to runGet()
end tell
-- everything is POSIX paths of stuff
-- set metaDataDict to {}
tell application "System Events"
set metaDataDict to make new property list item with properties {kind:record}
set metaDataFilePath to (fileLocation & "MetaData.plist")
set metaDataFile to make new property list file with properties {contents:metaDataDict, name:metaDataFilePath}
end tell
repeat with oneFile in allContents
set fileMetaDataDict to getMetaDataDict(oneFile)
display alert "3"
tell application "System Events"
tell property list items of metaDataFile
make new property list item at end with properties {kind:record, name:(name of (info for (oneFile as POSIX file))), value:fileMetaDataDict}
end tell
end tell
end repeat
end if
end getMetaData