plists for defaults write

Somebody just asked me a question about changing defaults. That triggered the next question on my side:

A shell command like

defaults read com.apple.TextEdit

yields

{
PMPrintingExpandedStateForPrint2 = 0;
UseEmbeddedCSS = 0;
UseInlineCSS = 1;
}

on my machine. That is an old style property list from the age of NeXTStep. The property list suite of System Events is still able to read that old style:


set x to "{
    PMPrintingExpandedStateForPrint2 = 0;
    UseEmbeddedCSS = 0;
    UseInlineCSS = 1;
}"

tell application "System Events"
	set y to make new property list item with properties {text:x}
	set z to value of y
end tell
get z

returns the record “{UseInlineCSS:“1”, UseEmbeddedCSS:“0”, PMPrintingExpandedStateForPrint2:“0”}” which is almost OK. (The numbers are not recognized as such.)

Is there any way to cause System Events to produce that old style? “defaults” is not really happy with the “modern” XML style, it seems.

Regards, Jürgen

Hello :slight_smile:

Defaults are perfectly happy, if you put in the correct key value pairs. That is, that you adress, and insiert, change, and delete elements in the correct order, or even build up new defaults files from scratch.

If memory serves me right, it is easier to use Satimage.Osax, than System Events.

There should be several posts here, where you can study examples.

Hi,

the “old” style is actually just the “modern” text representation of a non-string object (dictionary, array, date) by calling it’s objective-c description method.
As the shell interface is exclusively text based number values are coerced into their text equivalents and data objects are converted into a byte by byte hexadecimal string representation

Hello!

I just wanted to add that the utility plutil (man plutil) converts between the two formats and checks the syntax!

Good tip. plutil escaped me.

Jürgen