So there's this cool unix-shell thingy called "defaults" that
I've just become aware of. I've thrown together the following
object-wrapper as an example of using it:
Self = MacOS.appSelf();
// AppleScript's "quoted form of..."
//
String.prototype.toQuoted = function() {
return "'" + this.replace( /'/g, "\\'" ) + "'";
}
Prefs = {
plist : "My Amazing Preference Name", // don't include ".plist"
where : "~/Library/Preferences/", // note: don't quote "~/"
write : function( key, val ) {
Self.do_shell_script( "defaults write " + this.where +
this.plist.toQuoted() + " " +
String( key ).toQuoted() + " " +
String( val ).toQuoted()
);
},
read : function( key ) {
return Self.do_shell_script( "defaults read " + this.where +
this.plist.toQuoted() + " " +
String( key ).toQuoted()
);
}
}
Prefs.write( "favorite color", "plaid" );
Prefs.read ( "favorite color" ); //=> "plaid"
Goodnight,
-- Arthur