Simple use of PlistBuddy, plistbuddy
Simple use of PlistBuddy
Since PlistBuddy is not in Mac's default Path, we need to reference this tool through the absolute Path:
/usr/libexec/PlistBuddy --help
Let's take a look at PlistBuddy's simple print:
- Initializes an info. plist file.
Initialize info. plist
- Print the info. plist File
/usr/libexec/PlistBuddy -c "print" info.plist
- Enter the preceding command on the terminal as follows:
Add
/usr/libexec/PlistBuddy -c 'Add :Version string 1.0' info.plist
- Add an array field in two steps. Note:
Keys are separated by: And no space is allowed.
:
# First Add the key value/usr/libexec/PlistBuddy-c 'add: Application array 'info. plist # Add value yans67deMacBook-Pro: needfiles huangyg $/usr/libexec/PlistBuddy-c 'add: Application: string app1' info. plistyans67deMacBook-Pro: needfiles huangyg $/usr/libexec/PlistBuddy-c 'add: Application: string app2' info. plistyans67deMacBook-Pro: needfiles huangyg $/usr/libexec/PlistBuddy-c 'add: Application: string app3' info. plist
- Add a dictionary field in two steps:
# First Add the key value/usr/libexec/PlistBuddy-c 'add: Person dict 'info. plist # Add value,/usr/libexec/PlistBuddy-c 'add: Age string secret 'info. plist/usr/libexec/PlistBuddy-c 'add: Person: Name string yans67 'info. plist/usr/libexec/PlistBuddy-c 'add: Person: sex string boy 'info. plist/usr/libexec/PlistBuddy-c 'add: Person: weight string 65'info. plist
Output
- Print the corresponding field value:
/usr/libexec/PlistBuddy -c 'Print :Person' info.plist
- In array, we can also print a specific value according to the subscript.
/usr/libexec/PlistBuddy -c 'Print :Application:2' info.plist
Delete
- Delete the corresponding field value:
/usr/libexec/PlistBuddy -c 'Delete :Version' info.plist
Modify
- Modify the value of a field:
/usr/libexec/PlistBuddy -c 'Set :Application:1 string "thi is app1"' info.plist
Merge
- When there are two plist files, we can merge them.
# Merge A. plist into B. plist/usr/libexec/PlistBuddy-c 'merge A. plist' B. plist
The terminal will prompt that B. plist has duplicate key values, so the merge of this key value is skipped by default.
Before merging
Link: http://www.jianshu.com/p/2167f755c47e
Reference link: http://shaojunxiao.com/#/03/23/use plistbuddyto modify the info-plistfile /? Utm_source = tuicool & utm_medium = referral
Https://segmentfault.com/a/1190000002423661