Thanks to Geoff Norton in pointing me to NSDictonary and Baker, GJ for the 
example phonebook program, I was finally able to read a plist from OSX. It may 
not be pretty but I will port the code below in case anyone else needs help. I 
wasn't totally sure about the NSApplication.Main. I commented it out to keep 
the program from opening up a window. This is strictly a console app to help us 
manage our macs better. What is the correct way to do this?

Travis

static string GetPlistValue(string filepath, string key)
{
                //Clean up the pool errors
                using (var ns = new NSAutoreleasePool())
                {
                                //Connect to Apple framework
                                NSApplication.Init ();
                                //Commented out cause this is a console app
                                //NSApplication.Main (args);

                                //Create a new dictonary to hold our plist
                                NSDictionary plist = new NSDictionary();

                                //Check to see if the plist exists
                                if 
(NSFileManager.DefaultManager.FileExists(filepath))
                                {
                                                //Check to see if the plist has 
anything in it
                                                plist = 
NSDictionary.FromFile(filepath);
                                                if (plist != null)
                                                {
                                                                //return the 
value for our key
                                                                NSString 
valueKey = new NSString(key);
                                                                return 
plist.ValueForKey(valueKey).ToString();
                                                }else{

                                                                //The plist is 
empty
                                                                return "Empty 
plist";
                                                }
                                }

                                //Can't find the plist, correct path?
                                return "No plist found";
                }
}

From: [email protected] 
[mailto:[email protected]] On Behalf Of GARRISON, TRAVIS J.
Sent: Thursday, March 17, 2011 3:09 PM
To: [email protected]
Subject: [Mono-osx] reading and writing plists

We are looking for examples on how to read and write to the native plists 
included with Mac OSX. Most of the plists are in the binary format, which we 
can convert to the xml format if needed. We are trying to code a few tools to 
help us manage our macs better.

Thanks
Travis
_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to