- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
/usr/libexec/PlistBuddy -c "Set :cust_info:pid 94758476" com.apress.example.plist in Font
/usr/libexec/PlistBuddy -c "Set :cust_info:pid 94758476" com.apress.example.plist Generate QR Code ISO/IEC18004 In None Using Barcode creator for Font Control to generate, create QR Code ISO/IEC18004 image in Font applications. www.OnBarcode.comQR Generator In None Using Barcode generator for Font Control to generate, create QR image in Font applications. www.OnBarcode.comNOTE: If you run PlistBuddy from a directory other than the one containing the .plist file you re manipulating, you ll need to specify the full path of the .plist file to edit. See the PlistBuddy main page (note the capitalization) for more information on the utility. PlistBuddy is capable of much, much more, including copying values and merging .plist files. Print EAN13 In None Using Barcode encoder for Font Control to generate, create EAN13 image in Font applications. www.OnBarcode.comPrinting Barcode In None Using Barcode maker for Font Control to generate, create Barcode image in Font applications. www.OnBarcode.comCHAPTER 4: Property List Files
Create Code 128C In None Using Barcode creator for Font Control to generate, create Code 128 image in Font applications. www.OnBarcode.comBarcode Drawer In None Using Barcode maker for Font Control to generate, create Barcode image in Font applications. www.OnBarcode.comCocoa for Scripters
PDF 417 Generation In None Using Barcode drawer for Font Control to generate, create PDF 417 image in Font applications. www.OnBarcode.comEAN-8 Printer In None Using Barcode maker for Font Control to generate, create EAN8 image in Font applications. www.OnBarcode.comAs alluded to earlier in this chapter, Apple s Cocoa framework has native methods for reading and writing property list files. Cocoa is exposed to Python, Ruby, and Perl via the Objective-C bridge. While a full-out course on any of these scripting languages is beyond the scope of this book, we can give an overview for people who have some experience and just need examples of creating, writing, and reading .plist files. Why, though, would you want to use a language like Ruby or Python instead of the other command-line tools (plutil, PlistBuddy, and, particularly, defaults) and bash scripting From time to time, as a system administrator, you ll find yourself in a position where you d like a script to store its own preferences. Or, you d like to simply have a script analyze a .plist file and act on the contents in some manner. In many cases, bash scripting will be perfectly acceptable. However, for anything with a little more complexity, you may already be scripting in Python, Perl, or Ruby. While you can successfully use any of these, for demonstration purposes, we re going to use Python. NOTE: PyObjC is built into OS X 10.5 and above, and only with Python 2.5 and above. It s possible to use PyObjC with 10.4-based machines, but you ll need to compile and install PyObjC yourself. Mac OS X 10.5 ships with both Python 2.4 and 2.5, so be sure to stick with the default version of 2.5. Mac OS X 10.6 ships with both Python 2.5 and 2.6; both contain the Objective-C bridge support. Python, with PyObjC (the Objective-C bridge), turns working with property list files into a pretty trivial operation. Most importantly, you get the best of both worlds: Apple s APIs, along with Python s ease of use and the speed of the edit and run cycle (skipping the compile step of C-based languages). To see this in action, let s start with nearly the simplest example possible. Listing 4-1 contains write_plist.py, which demonstrates creating a dictionary that gets written to a .plist file. QR Code 2d Barcode Generation In Java Using Barcode drawer for Android Control to generate, create QR image in Android applications. www.OnBarcode.comQR Code JIS X 0510 Creator In Java Using Barcode generator for Java Control to generate, create QR image in Java applications. www.OnBarcode.comListing 4-1. write_plist.py #!/usr/bin/python2.5 from Foundation import NSMutableDictionary my_dict = NSMutableDictionary.dictionary() my_dict['color'] = 'blue' my_dict['count'] = 15 my_dict['style'] = 'fruit' success = my_dict.writeToFile_atomically_('com.apress.example.plist', 1) if not success: print "plist failed to write!" sys.exit(1) Generate Barcode In None Using Barcode maker for Software Control to generate, create Barcode image in Software applications. www.OnBarcode.comMaking 1D Barcode In Java Using Barcode encoder for Java Control to generate, create Linear 1D Barcode image in Java applications. www.OnBarcode.comCHAPTER 4: Property List Files
Barcode Reader In .NET Using Barcode reader for .NET framework Control to read, scan read, scan image in .NET framework applications. www.OnBarcode.comEAN128 Drawer In Java Using Barcode creation for Java Control to generate, create UCC-128 image in Java applications. www.OnBarcode.comUpon running this program, com.apress.example.plist will be created in the same working directory as the program itself. The .plist file will match the output that is shown in Listing 4-1. Let s examine this line by line to see how it works. The very first line----#!/usr/bin/python2.5----is a good reminder that Python version 2.5 or higher is required for PyObjC integration. This will not work on Tiger systems out of the box. EAN-13 Printer In Visual C# Using Barcode generation for VS .NET Control to generate, create UPC - 13 image in .NET applications. www.OnBarcode.comDrawing ECC200 In None Using Barcode encoder for Office Word Control to generate, create Data Matrix 2d barcode image in Word applications. www.OnBarcode.comfrom Foundation import NSMutableDictionary
Decode Data Matrix 2d Barcode In Visual C#.NET Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in .NET applications. www.OnBarcode.comGenerating UPC Symbol In Java Using Barcode encoder for BIRT reports Control to generate, create UPC-A image in BIRT reports applications. www.OnBarcode.comThis import is responsible for all of the magic here. While we could import all of Foundation, we ll import just the portion we need: NSMutableDictionary. PDF-417 2d Barcode Generation In None Using Barcode generator for Online Control to generate, create PDF 417 image in Online applications. www.OnBarcode.comDecoding Barcode In Java Using Barcode Control SDK for Java Control to generate, create, read, scan barcode image in Java applications. www.OnBarcode.commy_dict = NSMutableDictionary.dictionary() Typically, creating a dictionary in Python would use curly braces, like this: new_dict = {} Or, you can even fill it on creation: new_dict = {'color':'blue', 'count':15, 'style':'fruit'} However, we need to create a real Cocoa NSMutableDictionary object, so that s what we ve done. Nicely, we can now go on and treat that just like a Python dictionary: my_dict['color'] = 'blue' my_dict['count'] = 15 my_dict['style'] = 'fruit' You can use the Cocoa API for adding entries to a dictionary as well: my_dict.setValue_forKey_('stop', 'state') This would set the key state to store the value stop, and add the following to the .plist file once written out:
|
|