I’ve got a script of mine using some code from here that looks like this:
[code]-- configuration file
set myPlist to “com.BackupScript”
set AppConfig to ((path to preferences as Unicode text) & myPlist & “.plist”)
– load the configuration
set someFile to AppConfig
try
AppConfig as alias
do shell script “defaults write " & myPlist & " PromptForOverwrite -bool false”
do shell script “defaults write " & myPlist & " BasePath -string "” & userHome & “Dropbox” & “:"”
do shell script “defaults write " & myPlist & " BackupObjects -dict”
on error
display dialog “you broke it”
end try[/code]
That works OK and there is a dictionary created called ‘BackupObjects’.
However, I then want to add an array to the dictionary item that has the name ‘Snippets’ when then, in turn, contains some string items.
I’ve done a load of searching but can’t make it work.
Can anyone help? I’m also not sure if I should be using dictionaries or arrays so any pointers there would be good.
Thanks!
Model: Macbook Pro Core i7
AppleScript: AppleScript Editor version 2.3
Browser: Firefox 3.6.8
Operating System: Mac OS X (10.6)
You might check this post, and the links therein.
They show how to read/write a plist with System Events, and deal with the contents as an AppleScript record.
I find this much easier than using ‘defaults’
The writing part is great! Thanks for posting that.
Having a bit of trouble getting the reading part to work, though. I can read the file using ‘defaults read’ from before but the read method provided in the link above doesn’t do anything for me - it just says “Can’t get property list file”. The file’s there, though, as I can write to it just fine.