Most plist files found in the users/library/preferences/ are files that are binary.
When read with a plain text reader it always start with bplist00
Is there a way to ‘decode’ your own plist file too so it created a valid binary plist file?
Most plist files found in the users/library/preferences/ are files that are binary.
When read with a plain text reader it always start with bplist00
Is there a way to ‘decode’ your own plist file too so it created a valid binary plist file?
You can access plist data through MBS I’m pretty sure.
You can use the plutil command in a shell to convert XML formatted plists to binary format or binary format to XML format. The following article shows the format of the plutil commands to do it.
http://osxdaily.com/2016/03/10/convert-plist-file-xml-binary-mac-os-x-plutil/
Edit: Fixed the URL.
check out https://github.com/macoslib/macoslib I think there is some code in there to read/write plist files.
and I believe Xcode can translate them to XML for you as well
Not sure why, but when I click on the above some idiotic page appears. If I copy the text and paste it in to the browser URL field it works fine.
When you post a link, if you’re going to post the full url you don’t need to click the Link button
If you click the Link button make sure that the url=
part is the URL and the stuff between the tags becomes the link text.
Thanks for the replies. Will take a look at the MBS plugins (didn’t found it at first glance though).
e.g. NewCFObjectMBSFromXML to parse
http://www.monkeybreadsoftware.net/corefoundation-corefoundation-new-method.shtml#15
and CFObjectMBS.XML to get back XML.
NSDictionary has a function for reading and writing plist files. As does NSArray. No conversion required.
Although to read data in preference files, you should be using NSDefaults and not directly interacting with the preference files. This has been an Apple guideline since Mac OS X 10.0, Mac OS X 10.9 was the first OS version that I’m aware of which caches the preferences and manually editing the files (even deleting them) can result in weird things happening to the application.
and there is code in macoslib to do that
I’m sure its in AppleLib etc as well
[quote=313276:@Norman Palardy]and there is code in macoslib to do that
I’m sure its in AppleLib etc as well[/quote]
Am sure, I don’t know which implementation has what, the function you want is.
For writing, the function is:
- (BOOL)writeToURL:(NSURL *)url
atomically:(BOOL)atomically;
For reading a plist file you want:
+ (NSDictionary<KeyType,ObjectType> *)dictionaryWithContentsOfURL:(NSURL *)url;
In the end what I needed was CFPreferences.
This is the only API that makes it possible to create valid encoded plist files and use a plist filename not related to the bundle ID.
MBS plugins has this class. macosLib does not have it atm.
BTW NSDictionary does write plist files, but they are ASCII files (not binary).
CFPreferences is definitely in macOSLib
I see, using the convenience method then yeah, it can read plist files in any format but you are at Apple’s whim on what format it creates.
For more control you need to look at either “NSPropertyListSerialization” or “NSKeyedArchiver”, I’ve used the second and it’s pretty easy.
For CFDictionaryMBS class, I also have read/write methods:
http://www.monkeybreadsoftware.net/class-cfdictionarymbs.shtml