Edit PList file
  • 14 Nov 2024
  • 2 Minutes to read
  • Dark
    Light
  • PDF

Edit PList file

  • Dark
    Light
  • PDF

Article summary

The Edit PList file action allows you to modify PList files. This could be used to edit configuration files for a package for example.

General
TypeEdit PList file
Name

Actions are easier to comprehend and manage over time when they have a suitable name that accurately expresses what they do.

FileThe path to the targeted file.
Actions tableHere you can add, set, update or remove the name and the value of a certain key, inside dictionaries or arrays of the .PList file.
Advanced
ContextThe level at which the action is executed, User or Device.
VariablesIf this option is selected, then variables are supported within the action.

Filters
Here you can define conditions which determine if the action will be executed. For more information, see Filters.

Agent

It requires the Agent to be running.

Supported platforms

PlatformSupported
WebNo
WindowsYes
macOSYes

Example

We'll use the following PList for our examples.

<?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>CFBundleName</key>
	<string>TestApp</string>
	<key>CFBundleExecutable</key>
	<string>TestApp</string>
	<key>CustomFields</key>
	<dict>
		<key>CustomField1</key>
		<string>Test value</string>
		<key>CustomField2</key>
		<array>
			<string>Test value 1</string>
			<string>Test value 2</string>
			<string>Test value 3</string>
		</array>
		<key>CustomField3</key>
		<dict>
            <key>CustomSubField1</key>
			<string>Test value 1</string>
			<key>CustomSubField2</key>
			<string>Test value 2</string>
		</dict>
	</dict>
</dict>
</plist>

How to select a key

To select a key within a dictionary (dict element), use the name of the key. For example, to select 'CFBundleName' use CFBundleName. To select a key in a nested dictionary, separate the dictionaries by using '/'. For example CustomFields/CustomField1.

How to select an array element

To select an array element, use the index number (starting from zero). For example, to select the 'Test value 2' use CustomFields/CustomField2/1. You can use a negative number to count from the last element back. For example, if you want to select the last element in the array, you can use CustomFields/CustomField2/-1.

How to add an array element

To add an array element, use the 'Add action' and specify with the key the array. For example, to add an element to the 'CustomField2' array, use as key: CustomFields/CustomField2 or */CustomField2.

How to remove an array element

To remove an element of an array, use the 'Remove action' and specify the array element with the key. For example to remove the last element of the 'CustomField2' array, use as key: CustomFields/CustomField2/-1 or */CustomField2/-1. To remove all elements of the array, you can use CustomFields/CustomField2/* or */CustomField2/*.

Wildcards

Wildcards are supported. To select all values in the 'CustomFields' dictionary, use CustomFields/*. The same applies for arrays: CustomFields/CustomField2/*. A single '*' indicated a single level. For multi-level, use a double '*', for example **/CustomSubField1.

How to insert a PList fragment

To insert a PList fragment, use the 'Xml' type. The value should only describe a fragment without the XML or PList definition and it should always contain a single top element. For example:

<array>
	<string>Test value 1</string>
	<string>Test value 2</string>
</array>

Overview of the results depending on the type you are changing:

Dictionaries:

	/path/key:
		Set: overwrite key item
		Update: overwrite key item
		Add: add key item if it doesn't exist
		Remove: remove key item

	/path/ or /path/*:
		Set: overwrite all items
		Update: overwrite all items
		Add: not supported
		Remove: remove all items

Lists:

	/path/0:
		Set: overwrite first item
		Update: overwrite first item
		Add: insert before first item
		Remove: remove first item

	/path/-1:
		Set: overwrite last item
		Update: overwrite last item
		Add: insert before last item
		Remove: remove last item

	/path/ or /path/*:
		Set: overwrite all items
		Update: overwrite all items
		Add: add new item at the end of the list
		Remove: remove all items

Was this article helpful?

What's Next