Here’s my way around the AppleScript/PLIST communication problem. I am writing an AppleScript Studio application, and I needed a good, efficient way to set all sorts of properties. I created two subroutines, placed at the bottom of my script (outside the “on run” block); one to set properties, and one to read them.
to setPreferences about theKey at theType for theValue
do shell script ("defaults write " & myDomain & " " & (the quoted form of theKey) & " -" & theType & " " & (the quoted form of theValue) as text)
end setPreferences
and
to readPreferences about theKey
try
set theValue to (do shell script ("defaults read " & myDomain & " " & (the quoted form of theKey) as text)) as text
on error
set theValue to "" as text
end try
return theValue
end readPreferences
Of course, since I was only writing properties for myself, I created a global property at the very beginning of my script containing the Domain of my app:
property myDomain : "com.c8.VERB"
Note that this must be done outside of “on run,” “to setPreferences,” or any other blocks. With a fairly small reworking, you could change that to any application you need, and properties are changeable during runtime just like any other variable.
There is a built-in error catcher when reading preferences: if you attempt to read a property that does not exist, you will simply get an empty string “” back.
With this set up, it is really simple to set preferences:
setPreferences of me about "defaultRemoteHost" at "string" for "hal.local"
-- equivalent to: do shell script "defaults write com.c8.VERB defaultRemoteHost -string 'hal.local'"
.where at “string” identifies the type of the value: string, data, int, float, bool, date, array, array-add, dict, or dict-add.
It is equally easy to read values:
set theLocation to readPreferences of me about "defaultRemoteHost"
-- returns "hal.local"