read/write preferences

Need help with a script? This is the place to discuss how to get your code running!

read/write preferences

Postby sctell » Fri Jul 28, 2017 2:36 am

Just been messing with this.

The prelim docs suggest you can delete a preference.

To delete a preference, just write empty to it.


So I did this

Code: Select all
on mouseUp
    write empty to preference "TESTPREF"
end mouseUp


and ended up with this

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>TESTPREF</key>
   <string></string>
</dict>
</plist>


Therefore the key was not deleted.

Is it the docs incorrect or a bug?

All the best

Terry
sctell
 
Posts: 1111
Joined: Sun Jul 06, 2008 10:41 am

Re: read/write preferences

Postby sctell » Fri Jul 28, 2017 2:38 am

In addition this functionality seems to be based upon NSMutableDictionary.

Could the functionality be extended to allow users of SC supported access to Dictionaries?



All the best

Terry
sctell
 
Posts: 1111
Joined: Sun Jul 06, 2008 10:41 am

Re: read/write preferences

Postby codegreen » Fri Jul 28, 2017 8:41 am

Is it the docs incorrect or a bug?

It appears the behavior of one of the Toolbox APIs this feature called has changed subtly since that code was written, so it now produces a valid (albeit empty) CFString even when passed NULL input (which means we're no longer writing NULL to the CFPreference when you pass empty). I've fixed that, thanks.

Unfortunately (for you at least) this code does NOT actually do anything with NSMutableDictionaries, that's just an implementation detail (explicitly subject to change without notice) of how the underlying CFPreferences API works under the hood. Thus it can't be 'extended' to expose that ability for use by scripters ('cuz it ain't there now).

It's good idea though... ;-)

-Mark
codegreen
 
Posts: 1477
Joined: Mon Jul 14, 2008 11:03 pm


Return to Scripting in SuperTalk

Who is online

Users browsing this forum: No registered users and 1 guest

cron