10.4: Edit and save binary plist files in emacs, revisited

Jun 28, '05 10:45:00AM

Contributed by: popguru

Tiger only hintThis is an alternative method for this hint, which will allow you to edit binary .plist files in Emacs as text. This version will also save them as binary files again, transparently.

First, we need to create a wrapper script for plutil. I put mine in ~/bin, but you can put it wherever you prefer. Here's the contents:

#!/bin/sh

tempfile=/tmp/`basename $0`.$$
touch $tempfile
dd <&0 >$tempfile
plutil $* $tempfile 
dd <$tempfile >&1
All the script does is take data passed to it via standard input and save it to a temporary file, convert the temporary file with the plutil commmand, and write the contents of the file to standard output. This step is necessary because Emacs's auto-compression-mode uses standard output and standard input to pipe data, but plutil only acts on a physical file. (I tried piping to using plutil [arguments] /dev/stdin, but got errors.)

After creating the file, make it executable with this command (replacing /path/to/scriptfile with the actual path to your script):

chmod a+x /path/to/scriptfile
Finally, add this to your .emacs file:
;;; Allow editing of binary .plist files.
(if (null (require 'jka-compr nil t))
    (message "Warning: jka-compr not found.")
  (auto-compression-mode 0)
  (add-to-list 'jka-compr-compression-info-list
               [".plist'" 
                "converting text XML to binary plist" 
                "/path/to/scriptfile" ("-convert binary1") 
                "converting binary plist to text XML"
                "/path/to/scriptfile" ("-convert xml1") 
                nil nil "bplist"])
  (auto-compression-mode 1)
Restart Emacs and open up a binary .plist file. Go ahead and make some changes and save. The file will be updated and remain in binary format. Hope you find this useful.

Comments (6)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2005061422012079