Having trouble with code (as usual), trying to write to plist.
set tempScript1 to POSIX path of ((choose file) as text)
log "tempScript1 is: " & tempScript1
field1's setStringValue_(tempScript1)
log "Writing to .Plist"
do shell script "defaults write " & (((current application's NSBundle's mainBundle()'s bundlePath()) as text) & "/Contents/Info.Plist") & " script1Path " & tempScript1
log "Plist reads: " & (current application's NSBundle's mainBundle()'s objectForInfoDictionaryKey_("script1Path")) as string
set script1 to (current application's NSBundle's mainBundle()'s objectForInfoDictionaryKey_("script1Path")) as string
Everything seems to work except the writing to plist. It doesn’t return an error because it’s wrapped in a try, end try and on error but it doesn’t work either because the log has “Plist reads:” and blank. When I check the plist of the application, it’s blank too. This is annoying :@
Ok, I’ve tried it out now. Couple of things though…
When writing to .plist , it doesn’t like it if there’s a space anywhere in the name of the path. I know I can use delimiters to take out spaces, but I don’t know what to replace them with…
My .plist starts off blank, when I compile. I go to preferences (of my application) and pick a .scpt , the path gets written to the .plist fine. However, after that, if I choose a different script, it writes with no errors, but when it logs the .plist value, it comes up as the old value. Even if I quit it and relaunch, when it reads the .plist at startup, the value still has the old value. Why? And how to fix?
It seems that you’re going to change the path information in Info.plist frequently.
Info.plist is not the right place to do that.
user defaults, which reads/writes into an application specific property list file in ~/Library/Preferences is
designated for this purpose