How to use the command plutil (with examples)

How to use the command plutil (with examples)

  • Osx
  • December 25, 2023

plutil is a command-line utility that allows users to view, convert, validate, or edit property list (“plist”) files. Property list files are commonly used in macOS and iOS to store structured data. With plutil, users can interact with plist files by displaying their contents, converting them to different formats, and even editing them.

Use case 1: Display the contents of plist files

Code:

plutil -p file1.plist file2.plist ...

Motivation: Being able to view the contents of a plist file in a human-readable format can be helpful for understanding the data structure. This use case is especially useful for troubleshooting or debugging purposes when trying to identify the values stored within the plist file.

Explanation:

  • plutil: The command itself.
  • -p: Specifies the option to display the contents of the plist file in a human-readable format.
  • file1.plist file2.plist: Represents the paths or filenames of the plist files to be displayed.

Example output:

{
  "key1": "value1",
  "key2": {
    "nestedKey1": "nestedValue1",
    "nestedKey2": "nestedValue2"
  }
}

Use case 2: Convert plist files to XML format, overwriting the original files in-place

Code:

plutil -convert xml1 file1.plist file2.plist ...

Motivation: Converting plist files to XML format can be useful when working with tools or systems that require XML representation of configuration data. By overwriting the original files, the process becomes more streamlined.

Explanation:

  • plutil: The command itself.
  • -convert xml1: Specifies the option to convert the plist file to XML format.
  • file1.plist file2.plist: Represents the paths or filenames of the plist files to be converted.

Example output:

<?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>key1</key>
    <string>value1</string>
    <key>key2</key>
    <dict>
      <key>nestedKey1</key>
      <string>nestedValue1</string>
      <key>nestedKey2</key>
      <string>nestedValue2</string>
    </dict>
  </dict>
</plist>

Use case 3: Convert plist files to binary format, overwriting the original files in-place

Code:

plutil -convert binary1 file1.plist file2.plist ...

Motivation: Converting plist files to binary format can be beneficial for optimizing file size and reducing load times. It is particularly useful when working with applications that require binary plist files for performance reasons.

Explanation:

  • plutil: The command itself.
  • -convert binary1: Specifies the option to convert the plist file to binary format.
  • file1.plist file2.plist: Represents the paths or filenames of the plist files to be converted.

Example output: Binary plist files are not human-readable, so no output is provided here.

Use case 4: Convert a plist file to a different format, writing to a new file

Code:

plutil -convert xml1|binary1|json|swift|objc path/to/file.plist -o path/to/new_file.plist

Motivation: There may be situations where it is necessary to convert a plist file to a different format while preserving the original file. By specifying a new output file, users can retain the original plist file while having a converted version for specific use cases.

Explanation:

  • plutil: The command itself.
  • -convert xml1|binary1|json|swift|objc: Specifies the desired format for the conversion. The available options are xml1, binary1, json, swift, and objc.
  • path/to/file.plist: Represents the path or filename of the plist file to be converted.
  • -o path/to/new_file.plist: Specifies the desired location and filename of the output file.

Example output: A new plist file is created at the specified output path in the desired format, containing the converted contents of the original plist file.

Use case 5: Convert a plist file to a different format, writing to stdout

Code:

plutil -convert xml1|binary1|json|swift|objc path/to/file.plist -o -

Motivation: Writing the converted plist file to stdout can be useful when the output needs to be piped or redirected to another command or process. This allows for further processing or manipulation of the converted data.

Explanation:

  • plutil: The command itself.
  • -convert xml1|binary1|json|swift|objc: Specifies the desired format for the conversion. The available options are xml1, binary1, json, swift, and objc.
  • path/to/file.plist: Represents the path or filename of the plist file to be converted.
  • -o -: Specifies that the output should be written to stdout.

Example output: The converted plist file, in the desired format, is displayed in the terminal output. This allows users to capture, redirect, or process the converted data as needed.

Tags :

Related Posts

How to use the command "qm rescan" (with examples)

How to use the command "qm rescan" (with examples)

The “qm rescan” command is used to rescan all storages of a virtual machine in Proxmox VE and update the disk sizes.

Read More
How to use the command 'go bug' (with examples)

How to use the command 'go bug' (with examples)

The ‘go bug’ command is used to report a bug in the Go programming language.

Read More
Using certutil (with examples)

Using certutil (with examples)

Create a new certificate database To create a new certificate database, you can use the following command:

Read More