Display all defaults for any Cocoa app

Dec 26, '01 10:52:07AM

Contributed by: Anonymous

For any Cocoa app that uses the defaults system in the 'standard' fashion, the app will register defaults as it launches. If you launch the application using gdb (included with OS X), you can easily display all registered defaults.

Read the rest of the article for the how-to...

Start a terminal session, and launch the application to be viewed via the command line:

gdb /Applications/Mail.app/Contents/MacOS/Mail
This brings up gdb, ready to launch mail, so just type (at the gdb prompt), 'r' and then hit enter, and Mail.app will launch. You'll see a bunch of text go by, and eventually, Mail.app will show up on your screen.

Once the app is launched, go to the terminal window and type a ctrl-c. This will pause the app and give you a prompt. Then do this, entering each line below as a new line in gdb:
p $o = (unsigned int) objc_getClass("NSUserDefaults")
p $s = (unsigned int) sel_getUid("standardUserDefaults")
p $o = (unsigned int) objc_msgSend($o, $s)
p $s = (unsigned int) sel_getUid("dictionaryRepresentation")
p $o = (unsigned int) objc_msgSend($o, $s)
p $s = (unsigned int) sel_getUid("description")
p $o = (unsigned int) objc_msgSend($o, $s)
p (void) NSLog($o)
This will cause all of the registered defaults and their current values to be printed out.

[Editor's note: I just tried this with TextEdit, and it worked just as described - a very neat trick!]

Comments (9)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2001122610520724