cocoa.doc
cocoa.doc

Reputation: 93

Writing out complex things with the "defaults" command in Terminal

My Cocoa app writes out some involved things to user defaults using NSUserDefaults.

For example, if I type

defaults read com.mycompany.myapp SomeDefaultKey

in the Terminal, I get this output:

(
        (
        "2013-09-13 08:50:09 +0000",
        1
    ),
        (
        "2013-09-13 09:07:54 +0000",
        1
    )
)

so it's an array of two-element arrays each containing a date and a boolean.

How can I use the defaults command to add a new date-boolean array to the outer array?

Upvotes: 0

Views: 467

Answers (1)

CRD
CRD

Reputation: 53010

You use the -array-add option to do this - see man defaults. For example:

defaults write com.mycompany.myapp SomeDefaultKey -array-add '("2013-09-13 08:50:09 +0000", 2)'

The added value is an array - the ( & ) - of two items - "2013-09-13 08:50:09 +0000" and 2. The single quotes (') surround the value and basically you can provide any value in the format defaults itself would display it.

Upvotes: 1

Related Questions