Plistbuddy tool Use

Source: Internet
Author: User

PlistBuddy
PlistBuddy is a tool for reading and writing plist files on the command line in a Mac system. Can be used to read or modify the contents of a plist file.

PlistBuddy tool path
/usr/libexec/PlistBuddy
You can create a soft connection in the /usr/local/bin/ directory and you can use the PlistBuddy command directly.
# Cannot use the PlistBuddy command directly
Ln -s /usr/libexec/PlistBuddy /usr/local/bin/PlistBuddy
View help
/usr/libexec/PlistBuddy --help
Manipulating the plist file
Print the info.plist file
/usr/libexec/PlistBuddy -c "Print" info.plist
Print the corresponding value of the field
# print the field name value in info.plist
/usr/libexec/PlistBuddy -c 'Print :name' info.plist

#Script to get the field name value in the plist file and assign it to the variable
Name=$($PlistBuddy -c "print :name" info.plist)

# print array field testArr item 0
/usr/libexec/PlistBuddy -c 'Print :testArr:0' info.plist
Add field
Field Type
String
Array
Dict
Bool
Real
Int
Date
Data
# string Type: Add a field to the test.plist file Version value is 1.0.0
/usr/libexec/PlistBuddy -c 'Add :Version string 1.0.0' test.plist
# Array Type: Add an array field to the test.plist file AppArr

# 1. Add a key value
/usr/libexec/PlistBuddy -c 'Add :AppArr array' test.plist

# Note: The keys are separated by : and there can be no spaces:

# 2. Add value value app1 , app2
/usr/libexec/PlistBuddy -c 'Add :AppArr: string app1' test.plist
/usr/libexec/PlistBuddy -c 'Add :AppArr: string app2' test.plist
# Dictionary Type: Add an array field to the test.plist file AppDic

# 1. Add a key value
/usr/libexec/PlistBuddy -c 'Add :AppDic dict' test.plist

# 2. Add value value name , age
/usr/libexec/PlistBuddy -c 'Add :AppDic:name string Tom' test.plist
/usr/libexec/PlistBuddy -c 'Add :AppDic:age string 100' test.plist
Delete field
# Delete the fields in test.plist Version
/usr/libexec/PlistBuddy -c 'Delete :Version' test.plist
Modify field values
# Modify string type
/usr/libexec/PlistBuddy -c 'Set :version "1.1.1"' test.plist

# Modify array type. Modify the 0th value of the array in the AppArr field.
/usr/libexec/PlistBuddy -c 'Set :AppArr:0 "this is app1"' test.plist

# Modify the dict type. Modify the value of name in the AppDic field
/usr/libexec/PlistBuddy -c 'Set :AppDic:name "Jim"' test.plist
Merge two plists
# Merge A.plist into B.plist. With the same field, an overwrite will occur.
/usr/libexec/PlistBuddy -c 'Merge A.plist' B.plist

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.