# read plist files from command line?



## avramd (Apr 18, 2002)

Can anyone tell me if there is a command line tool to read values out of plist files?

I'm trying to write a script to automate installing the Balthisar Ghostscript Network Printer package, and I want it to check the version of the LPR module before replacing it. I wanted to do something cleaner than just parsing it's Info.plist file in perl.


----------



## lethe (Apr 18, 2002)

the 'defaults' command is what you are looking for.  check out the man pages.  here are some highlights

defaults domains will tell you all the domains of preferences available.

default read domainname reads some domain s preferences

example: defaults read com.omnigroup.OmniWeb will output the preferences of OmniWeb.

defaults read com.omnigroup.OmniWeb StartPage will tell you what omniweb is using for a start page.

you can write preferences this way too


----------



## avramd (Apr 18, 2002)

I actually had already tried defaults. The trouble is, the plist file I want to read is not actually a preferences file. It's 

/System/Library/Printers/IOMs/LPRIOM.plugin/Contents/version.plist

From what I can tell, there is no way to get defaults to parse a specific file.


----------



## ksv (Apr 18, 2002)

Try "sudo pico /System/Library/Printers/IOMs/LPRIOM.plugin/Contents/version.plist"
Pico is a great text editor for editiong .plist files


----------



## genghiscohen (Apr 18, 2002)

If you have the Developer Tools installed, PropertyList Editor will give you a very clean and easy-to-read listing of values for any .plist file.


----------



## lethe (Apr 18, 2002)

those are both nice tools, but if you look carefully, you will see that this guy needs this for a script, so pico and property list editor are not viable options.  defaults is a good bet, but avramd, you re right, i can t see how to make defaults read a specific file.  seems stupid for it not to be able, but ...

sorry.  guess you ll have to parse it yourself.  i ll let you know if i think of anything


----------



## avramd (Apr 22, 2002)

That's great, I'll give it a try. It'll be a few days before I can get back to this project, but I'll let you know how it works out.

Thanks for going through the trouble - this is a lot more of a response than I expected to get from a bulletin board!


----------



## rharder (Oct 5, 2002)

Anyone ever determine if there is a plist command line editor? Or a secret flag to make defaults read an arbitrary file?

-Rob


----------



## fddi1 (Oct 5, 2002)

Well, since plist is literally an XML file, I guess you can write a perl script using the XML parser modules to get the values you want.


----------



## rharder (Oct 7, 2002)

OK, next stop: Apple OpenSource repository. Maybe 'defaults' is part of Darwin, and maybe I can tell if there's a hidden command line switch.

-Rob


----------



## antweiss (Nov 22, 2010)

read any plist file with defaults: http://unixjunkie.blogspot.com/2007/01/use-defaults-to-manipulate-any-plist.html


----------



## Roodavis (Apr 7, 2011)

I can't say that I have tried reading "all" plist files with defaults, but I use Apple Remote Desktop with the defaults command to read and write to several plist files daily with no problem. The one thing I notice in this thread is that everyone is including the ".plist" in the file name. I only use the full path without the .plist extension. For example I have several software update servers and need to direct clients to different servers depending upon their OS. Rather than trying to remember if I have redirected a client or maintaining a database of which machines have been redirected I just send this command first: 

"defaults read /Library/Preferences/com.apple.SoftwareUpdate"

and ARD returns the current settings on that machine.

I just tried including the .plist extension and got an error stating that the domain com.apple.SoftwareUpdate.plist does not exist

YMMV

Rick Davis


----------

