I have a plist like so:

<?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">
    <key>Delete Me</key>
    <key>Keep Me</key>

How do I delete the key-pair "Delete Me"?

1 Answer 1

defaults delete /path/to/file Delete\ Me

FWIW, I'd avoid having spaces in the keynames. You could try single quotes instead of escaping it.

Also: you don't need the file extension .plist in the filepath.

Alternatively, you can open it in BBEdit or Xcode (both of which will handle conversion to and from binary plists on the fly) and delete the relevant portion (key and string) directly. Other text editors may also do the same.

  • I can't verify the result after running that command because it changed the format of the plist to bplist. Do you know a way to keep it as XML text? Jul 22, 2021 at 7:44
  • You can verify it with defaults read. It should return that the key is not found. Or, see my additions to the answer. For what app/process is this plist? Can the process read it as binary? There is the plutil command for converting the format.
    – benwiggy
    Jul 22, 2021 at 9:45
  • Thank you, yeah I just got plutil to convert it back to text. do shell script "plutil -convert xml1 '<posixPath>'" Jul 22, 2021 at 10:04
  • Is this part of some larger process? Other solutions to the broader problem might be possible.
    – benwiggy
    Jul 22, 2021 at 10:43
  • It's part of a library script. I have a session.applescript that I don't use directly, it has setValue, getValue, and now I want to have a deleteValue handler. It's used by other standalone scripts to store some current ID/value, for example. Jul 22, 2021 at 23:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .