Creating A Property List File
Creating A Property List File
- Subject: Creating A Property List File
- From: Luther Fuller <email@hidden>
- Date: Tue, 18 Mar 2008 17:00:39 -0500
There has been some discussion, in various threads, during the past
couple of months concerning the creation of a new property list file.
I usually do this by copying a default .plist file, but today I
needed to create one where there was no file to copy. Here's a
handler to to the job, or at least start you towards a variation on a
theme.
(Getting the last line took awhile. There is a null string (""), a
null integer (0) and a null list ({}), but @#$! there is no null
record ({:}). ... and I absolutely positively needed a null record.)
set newFileLoc to choose folder
my makeNewPlist(newFileLoc, "testplistfile")
on makeNewPlist(newFileLoc, fileName)
set posixLoc to (quoted form of (POSIX path of newFileLoc))
do shell script "defaults write " & posixLoc & fileName & " _ _"
-- creates the new property list file with dummy value
tell application "Finder" to set newPlistAlias to (file (fileName &
".plist") of newFileLoc) as alias
set defaultRecord to {|anInteger|:3, |aString|:"abc", |anArray|:{10,
20, 30}, |aBoolean|:true, |aRecord|:{a:"a", b:"b"}}
tell application "System Events"
POSIX path of newPlistAlias
set value of property list file the result to defaultRecord
-- over-writes the newly created plist file
end tell
do shell script "defaults write " & posixLoc & fileName & "
'EmptyDictionary' -dict"
-- adds an empty dictionary to the root dictionary.
-- this last line is optional. In case you need an empty dictionary.
end makeNewPlist -------------------------------
Now, open the new file with Property List Editor to see what you have.
(I wrote this in 10.4.11. Let us know if it works in 10.5.x, also.)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden