Perl Plist

Perl Plist Script and Examples

This script contains perl code that uses the PerlObjCBridge to read and modify Mac OS X plist format files. Plist files are ubiquitous on Mac OS X. I originally wrote 2 articles about this (article 1 and article 2) and my intention was to use them for personal projects but they have become so critical at work (Mac OS X system administration, I use it in nearly 30 scripts) I think I would feel handicapped if I didn't have them. So I keep improving and working on these scripts. Here is the latest version and some script examples and utilities.

Watch a presentation on this.

If you have questions, don't hesitate to contact me!

Download

Features

Features of the perlplist.pl script.

Features added in 8.3.12.

Features added in 8.3.13.

Features added in 8.3.14.

Features added in 8.3.15.

Features added in 8.3.16.

Known issues.

Features of the script examples.

Examples

james% sudo superDefaults.pl /private/var/db/launchd.db/com.apple.launchd/overrides.plist --add -d com.openssh.sshd -d Disabled -b 0

james% sudo superDefaults.pl ~/Library/Preferences/com.apple.Safari.plist --add -d WebKitJavaScriptCanOpenWindowsAutomatically -b 0

james% sudo superDefaults.pl /Library/Preferences/com.apple.AppleFileServer.plist --add -d guestAccess -b 0

james% sudo superDefaults.pl /Library/Preferences/com.apple.Bluetooth.plist --add -d BluetoothAutoSeekHIDDevices -b 0

james% sudo superDefaults.pl /Library/Preferences/DirectoryService/DSLDAPv3PlugInConfig.plist --add -d "LDAP Server Configs" -a 0 -d "Record Type Map" -a 0 -d "Attribute Type Map" -a 4 -d "Native Map" -a 0 -s "#/Users/kiosk"

james% sudo superDefaults.pl /etc/authorization --add -d rights -d system.privilege.taskport.debug -d class -s allow

james% sudo superDefaults.pl /Library/Preferences/.GlobalPreferences.plist --add -d "com.apple.ColorSync.Devices" -d "Device.mntr.756E6B6E-0000-0717-0000-00005B81C5C0" -d "CustomProfiles" -d "1" -s "/Library/ColorSync/Profiles/Projector Profile.icc"
james% plcat test1.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>3</key>
	<array>
		<string>1</string>
	</array>
	<key>1</key>
	<string>A</string>
	<key>2</key>
	<dict>
		<key>2</key>
		<string>B</string>
	</dict>
</dict>
</plist>

james% plcat test2.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>3</key>
	<array>
		<string>1</string>
		<string>2</string>
	</array>
	<key>2</key>
	<dict>
		<key>1</key>
		<string>A</string>
	</dict>
</dict>
</plist>

james% pldiff test1.plist test2.plist

> /{3}/[1]/2
< /{1}/A
< /{2}/{2}/B
> /{2}/{1}/A

james% plcat test1.plist test2.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>3</key>
	<array>
		<string>1</string>
		<string>2</string>
	</array>
	<key>1</key>
	<string>A</string>
	<key>2</key>
	<dict>
		<key>1</key>
		<string>A</string>
		<key>2</key>
		<string>B</string>
	</dict>
</dict>
</plist>

Python

Philip Rinehart at Yale loves Python. He sent me this Python version of get_ip (it doesn't read binary plists afaik, but you can install and include pyobc to get around this, or you can run plutil -convert xml1 on the file first...). This is a lot cleaner than the perlplist examples.

Comments

I'm not a traditional website guy and so I don't have comment fields. If you would like to leave a comment, email me and I'd be happy to add them to this page.

Clickochet Community Ads (ads for ads marketplace)