Find and Edit Plist

The Problem

Have you ever wondered how people figure out what commands they use to edit apple plists? I came across a response to a question about a plist that covered one such way of reverse engineering plists, including binary plists. Its a simple solution, with only a couple steps and it made me realize that everyone else just posts the solution to the problem and doesn’t post their work too. Like my math teachers always told me, “show your work”. So, with that in mind I wanted to do a write up of the process noach covered in the link above, but in my own words.

Overview of the Process

  1. Find the plist that is being changed
  2. Get a before and after copy of the plist
  3. Compare the before and after files for any difference
  4. Test the command and verify it will work
  5. Automate the change so you can duplicate the process

Finding the plist

Most of the time, there will be a plist the relates to the setting or preference that you want to change. Often, the plist will be in one of two locations:

  1. /Library/Preferences/ – which is the systems preferences location
  2. /Users/<specific user>/Library/Preferences/ – which are user specific settings

Apple-plistsPlists names usually look like backwards domain names, like Often, you can make a pretty good guess as to what the plist relates too. Like the from folder /Library/Preferences/ probably has something to do with the systems Bluetooth settings. If your not sure what plist you are dealing with, you can use something like fseventer, which will show you any file changes that take place while it is running. You just launch fseventer, make the changes using the GUI that you want to find the plist for, then see what fseventer tells you.

Get a Before and After Copy

Simple idea here. Configure the setting in the GUI you want to figure out the command for, backup the “before” plist file, change that very setting again to something else (doesn’t matter what), make another backup of the “after” plist file.

This command will put a copy of the plists on your current users desktop:

make your change then issue the command again but renaming the backup file to after

Compare the Before and After Files

The diff command is a simple but very useful command to compare files and their contents. To compare two files just list them after the diff command.

Since the plist I’m looking at is a binary plist I got the following output:

If they were just text files rather then binary I would have gotten the actual changes to my screen. To see the actual change that took place inside a binary file you need to convert it to xml and compare the converted text. I followed noach’s advice and used an alias for this.

and actually got the details of the plist change:

This tells us that the key “ControllerPowerState” changed from “0” to “1” when I made the configuration change in the GUI (i.e. turned on the bluetooth adapter).

The Command and Testing it

In OS X the command “defaults” is used to edit system and application preferences. You can read more about the command on its man page.  Lets use the defaults command to check our setting, change it, then verify the change took place.

# Check the current plist setting

I got “0” as the current setting.  Now lets change the setting.  Since mine is an “<integer>” and is 0 or 1 it is considered a bool. So I’ll use the bool switch in the defaults command to change mine from 0 to 1. Note that I have to use “sudo” to tell the system I have root privileges and am allowed to edit plist.

This time I got back a “1”, so it worked!  We now know we can make this change through the command line, which means we can script the change and automate it on all the systems that we manage.  Do note that defaults edits the saved settings of an application, so you won’t see the change reflected in the GUI (like system preferences) until the plist (i.e. saved settings) is reloaded again.  In my case, the bluetooth adapter turned on after I restarted the computer. In some cases you will just need to close and re-open system preferences or your application to get the saved settings to load and see them reflected in the GUI.

Automate the Change

Now, if you have a need like I do to push this change out to 2,000 computers you will need t0 script the change then run that script on all 2,000 computers.

Create the Script

I will have to cover scripting details in a post of its own.  But this script is pretty strait forward so lets just take a look at it here.  It is just the script bash declaration, the command we figured out, and the all clear exit command.

Just save the file as something like and make it executable by issuing the chmod command on it.

 Run the Script on Your Computers

To do this you should use a software management system like Munki, Filewave, or Casper.  But if you don’t have one of those set up yet you can use a tool like Apple Remote Desktop to send the commands to computers that need to run it.

Interested In A Free Installer?

Our custom Wifi On/Off script has been a popular post!
This script automatically turns off the wireless interface on a computer when it is connected to a wired network, and turn the wireless interface back on when it is disconnected from the wired network.
This script has two main benefits:
  1. Network connection failover
  2. Eliminates unnecessary wireless traffic, and Multi-homed computers.
We are now offering a pkg installer for this script to anyone that signs up for our mailing list.