read plist files from command line?

Discussion in 'Mac OS X System & Mac Software' started by avramd, Apr 18, 2002.

  1. avramd

    avramd Registered

    Joined:
    Dec 1, 2000
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Mystic, CT
    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.
     
  2. lethe

    lethe Registered

    Joined:
    Oct 4, 2001
    Messages:
    689
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    US
    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
     
  3. avramd

    avramd Registered

    Joined:
    Dec 1, 2000
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Mystic, CT
    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.
     
  4. ksv

    ksv web developer

    Joined:
    Nov 19, 2000
    Messages:
    3,000
    Likes Received:
    0
    Trophy Points:
    36
    Location:
    Trondheim, Norway
    Try "sudo pico /System/Library/Printers/IOMs/LPRIOM.plugin/Contents/version.plist"
    Pico is a great text editor for editiong .plist files ;)
     
  5. genghiscohen

    genghiscohen Membrum virile

    Joined:
    Sep 30, 2001
    Messages:
    805
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Free-lance writer and professional loon
    Location:
    Sea of Tranquility
    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.
     
  6. lethe

    lethe Registered

    Joined:
    Oct 4, 2001
    Messages:
    689
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    US
    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
     
  7. avramd

    avramd Registered

    Joined:
    Dec 1, 2000
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Mystic, CT
    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!
     
  8. rharder

    rharder Do not read this sign.

    Joined:
    Mar 29, 2001
    Messages:
    1,189
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Virginia, USA
    Anyone ever determine if there is a plist command line editor? Or a secret flag to make defaults read an arbitrary file?

    -Rob
     
  9. fddi1

    fddi1 Registered

    Joined:
    Apr 10, 2001
    Messages:
    40
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Virginia, U.S.
    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.
     
  10. rharder

    rharder Do not read this sign.

    Joined:
    Mar 29, 2001
    Messages:
    1,189
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Virginia, USA
    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
     
  11. antweiss

    antweiss Registered

    Joined:
    Nov 22, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
  12. Roodavis

    Roodavis Registered

    Joined:
    Jan 7, 2006
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Education Software Specialist
    Location:
    Erlanger, Kentucky
    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
     

Share This Page