Ever wished you could do something like this:
defaults read com.apple.loginitems read \
SessionItems.CustomListItems.Name
…to get a list of the ‘Name’ attributes of all your configured login items? How about to print out their paths?
defaults read com.apple.loginitems read \
"SessionItems.CustomListItems.CustomItemProperties.com\.apple\.loginitem\.legacyprefs.Path"
Doesn’t work so well does it? You can only use the defaults command to read something from the root of that property list.
I am therefore happy to announce the existence of my latest open-source project, NestedPlistEditor. This implements ‘defaults-nested’, a re-implementation of the standard tool which will follow key-value paths for both reading and writing values.
Not everything defaults supports is handled yet, but most things are. Nested parameters are handled in the read and write commands at present, and it includes a new KVC-style array-index operator: item.@index(2) will access the second value in the array referenced by the key path to ‘item’. This works for both reading and writing (although for writing the given index must be less than or equal to the number of values currently in the target array.
Grab the source here. Oh, and here’s the proof that it works:
[jim@Jims-iMac:..NestedPlistEditor/]% build/Release/defaults-nested read \
com.apple.loginitems SessionItems.CustomListItems.Name
(
GrowlHelperApp,
iTunesHelper,
ChaxHelperApp,
SqueezeHelper,
"Dropbox.app",
Clips
)
[jim@Jims-iMac:..NestedPlistEditor/]% build/Release/defaults-nested read \
com.apple.loginitems \
"SessionItems.CustomListItems.CustomItemProperties.com\.apple\.loginitem\.legacyprefs.Path"
(
"/Users/jim/Library/PreferencePanes/Growl.prefPane/Contents/Resources/GrowlHelperApp.app",
"/Applications/iTunes.app/Contents/Resources/iTunesHelper.app",
"/Users/jim/Library/ScriptingAdditions/ChaxAddition.osax/Contents/MacOS/ChaxHelperApp.app",
"/Users/jim/Library/PreferencePanes/Squeeze.prefPane/Contents/Resources/SqueezeHelper.app",
"/Applications/Dropbox.app",
"/Applications/Clips.app"
)