Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Cleaner display for 'defaults domains' command UNIX
The defaults system in Mac OS X allows you to manipulate application and system preferences (.plists) from the CLI. In order to display the list of available domains, you can type defaults domains, but the output is all on one line with domains separated by commas (see this previous hint). The following command will translate those commas into newlines, and then paginate the output with more:
  defaults domains | tr ',' '\n' | more
This still leaves some lines beginning with spaces, but I haven't yet figured out how to remove those, too.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[3,063 views]  

Cleaner display for 'defaults domains' command | 12 comments | Create New Account
Click here to return to the 'Cleaner display for 'defaults domains' command' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Cleaner display for 'defaults domains' command
Authored by: jzsimon on Apr 28, '03 11:22:34AM
> This still leaves some lines beginning with spaces, but I haven't yet figured out how to remove those, too.

Try this:
defaults domains | sed 's/, /\
/g' | more

It uses sed to change all combinations of 'comma space' to a newline. It works because the first line ends in \, which is an escape of the next character which is an escaped newline.

[ Reply to This | # ]

Cleaner display for 'defaults domains' command
Authored by: rtl on Apr 28, '03 11:30:11AM
Another way: defaults domains | tr -d ' ' | tr ',' '\n' | more

[ Reply to This | # ]
Cleaner display for 'defaults domains' command
Authored by: jzsimon on Apr 29, '03 11:19:33AM

My code changed between its preview and its posting. The end of
the line beginning with "default" should end in two backslashes,
not one. Same for the final sentence which should read: ... line
ends in backslash backslash, which is an escaped...



[ Reply to This | # ]
Cleaner display for 'defaults domains' command
Authored by: bluehz on Apr 28, '03 12:00:02PM
this removes leading and trailing whitespace (if any exists):
defaults domains | tr ',' '\n' | sed 's/^[ \t]*//;s/[ \t]*$//
' | more
(should be all one line of code - don't know why its being autowrapped here these days)

[ Reply to This | # ]
Cleaner display for 'defaults domains' command
Authored by: Eravau on Apr 28, '03 12:13:31PM

Of the three posted so far, this is the only one that seems to
work.

-Eravau (Tony Colter)
http://www.tonycolter.com/photos/



[ Reply to This | # ]
Cleaner display for 'defaults domains' command
Authored by: aranor on Apr 28, '03 05:54:22PM

Quick tip:

I took that last command and copied it into a file I called domainlist. I then created a ~/Scripts directory and put the domainlist file in that. I put the Scripts directory into my path in my .tcshrc file. Now, whenever I want to look at the domains, I just type 'domainlist' and I see them. In addition, if I want to find a certain pref file name, I type 'domainlist | grep -i blah' and it will show all domains that include the text 'blah' in them.

The reason I did this was because I couldn't get it to work with the alias command because of problems escaping everything. But it works nicely.



[ Reply to This | # ]
Cleaner display for 'defaults domains' command
Authored by: aranor on Apr 28, '03 05:56:20PM

Oh, one important thing I forgot was to say that I also ran 'chmod 777 ~/Scripts/domainlist' to make it executable.



[ Reply to This | # ]
Cleaner display for 'defaults domains' command
Authored by: discordantus on Apr 28, '03 06:23:57PM
or in perl:

defaults domains | perl -e 'while(<STDIN>){~s/,\s*/\n/ g;print}'

this will remove spaces at the beginning.

[ Reply to This | # ]

Cleaner display for 'defaults domains' command
Authored by: meELOISE on Apr 29, '03 01:05:00PM
not that perl is probably the way to go here, but to clean up the specials and shorten a bit:

defaults domains | perl -pe 's/,\s*/\n/g'

[ Reply to This | # ]

Cleaner display for 'defaults domains' command
Authored by: meELOISE on Apr 29, '03 01:11:42PM
hmm, how to get the backslashes? The showed up in the preview...:

code, single slash: defaults domains | perl -pe 's/,\s*/ \n/g'

code, double slash: defaults domains | perl -pe 's/,\s*/ \n/g'

pre, single slash:

defaults domains | perl -pe 's/,\s*/\n/
g'

pre, double slash:

defaults domains | perl -pe 's/,\s*/
\n/g'


[ Reply to This | # ]
Oh Lordy
Authored by: yoel on Apr 28, '03 11:13:08PM
Props to anyone crazy enough to write a huge-ass sed expression, but how about:

defaults domains | tr -s ', ' '\n' | more


[ Reply to This | # ]
Cleaner display for 'defaults domains' command
Authored by: creator_x on Apr 29, '03 09:49:43AM

defaults domains | tr ',\ ' '\n' | more

this works just fine for me.



[ Reply to This | # ]