Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Temp File Unnecessary' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Temp File Unnecessary
Authored by: EatingPie on Jun 13, '05 12:58:45PM

Good hint. A nice starting point for a mode... only thing needed is a re-convert to binary for the save function.

That said, my addition: No need for the /tmp/temp.plist file.

Change the "format" command to read like so:


     (format "/usr/bin/plutil -convert xml1 -o /dev/stdout %s"
             (shell-quote-argument (buffer-file-name)))

There you have it.

-Pie

---
-Pie


[ Reply to This | # ]

reconverting (was: Temp File Unnecessary)
Authored by: rflo on Jun 13, '05 01:24:23PM

Eating Pie wrote:

> A nice starting point for a mode... only thing needed is a re-convert
> to binary for the save function.

Actually, reconverting really isn't needed. An application that uses binary .plist files, like Safari, will convert the .plist to binary form the next time it is saved at program exit or when the perferences are changed.

---
Ronald Florence



[ Reply to This | # ]
reconverting (was: Temp File Unnecessary)
Authored by: klktrk on Jun 13, '05 02:25:15PM

That does not always seem to be the case. My sequence:
Closed Safari. Edited binary .plist file in emacs as per hint.
saved the changes in emacs.
opened the com.apple.Safari.plist file in BBEdit, noticed it was in XML text format
opened Safari. Closed Safari
opened the com.apple.Safari.plist file in BBEdit, noticed it was STILL in XML text format.



[ Reply to This | # ]
reconverting (was: Temp File Unnecessary)
Authored by: rflo on Jun 13, '05 02:55:51PM

klktrk writes:

> That does not always seem to be the case. My sequence:
> Closed Safari. Edited binary .plist file in emacs as per hint.
> saved the changes in emacs.
> opened the com.apple.Safari.plist file in BBEdit, noticed it was in XML > text format
> opened Safari. Closed Safari
> opened the com.apple.Safari.plist file in BBEdit, noticed it was STILL > in XML text format.

Look at the modified times on the preferences file. If you changed nothing in Safari, Safari would have no reason to resave the preferences file. When you do change something in Safari, it will save its preferences as a binary XML file.

---
Ronald Florence



[ Reply to This | # ]
reconverting (was: Temp File Unnecessary)
Authored by: GaelicWizard on Jun 13, '05 06:29:19PM

There is no need to convert back to binary, it is an identical representation of the XML. Personally, I would like to change the preference so that ALL plists are back in XML like they were pre-Tiger.

---
Pell



[ Reply to This | # ]
That doesn't work
Authored by: steike on Jun 14, '05 01:10:53PM

It seems to work, but you get a "/dev/stdout: Operation not supported" at the end of the file... notice the comment :-)



[ Reply to This | # ]
Crap!
Authored by: EatingPie on Jun 14, '05 02:13:03PM

Tested my change, and didn't see that.

I'll see if I can come up with a workaround inside emacs.


---
-Pie
<http://www.storybytes.com>



[ Reply to This | # ]
YES! It DOES WORK... Now!
Authored by: EatingPie on Jun 14, '05 04:17:24PM

Take my original...


     (format "/usr/bin/plutil -convert xml1 -o /dev/stdout %s"
             (shell-quote-argument (buffer-file-name)))

And after the close of the "when" statement, add:


  (save-excursion
    (goto-char (point-max))
    (previous-line 1)
    (if (looking-at "/dev/stdout: Operation not supported")
        (kill-line 1)))

Like I said, the temp file is not necessary! :)

---
-Pie


[ Reply to This | # ]

Temp File Unnecessary -- summary
Authored by: chris2 on Oct 30, '05 07:08:02AM
a great tip! as a summary of the other suggestions, and extra code to resave in binary foramt where appropriate: (note 'write-file advise is commented out as an easy way to save as xml instead.

(add-to-list 'auto-mode-alist '(".plist'" . visit-bplist))
(defvar plist-converted-binary nil
  "Buffer local variable indicating if file came from binary-plist.")
(make-variable-buffer-local 'plist-converted-binary)

(defun visit-bplist ()
  (when (string-match "^bplist" (buffer-string))
    (message "Reading in binary plist")
    (shell-command-on-region 
     (point-min) (point-max)
     (format "/usr/bin/plutil -convert xml1 -o /dev/stdout %s"
	     (shell-quote-argument (buffer-file-name))) t t)
    (save-excursion
      (goto-char (point-max)) (previous-line 1)
      (if (looking-at "/dev/stdout: Operation not supported") (kill-line 1)))
    (xml-mode)
    (set-buffer-modified-p nil)
    (setq buffer-undo-list nil)
    (setq plist-converted-binary t)))

(defadvice save-buffer (after convert-plist (&optional args))
  (when plist-converted-binary
    (shell-command
     (format "/usr/bin/plutil -convert binary1 %s"
	     (shell-quote-argument (buffer-file-name))) nil nil)
    (message "Wrote bplist %s" (buffer-file-name))))
(ad-activate 'save-buffer)

;; (defadvice write-file (after convert-plist (filename &optional confirm))
;;   (if plist-converted-binary
;;       (shell-command
;;        (format "/usr/bin/plutil -convert binary1 %s"
;; 	       (shell-quote-argument filename))
;;        nil nil)))
;; (ad-activate 'write-file)


[ Reply to This | # ]