一般我们编辑plist文件都是直接打开,用PlistEditor什么的进行可视化编辑,但是如果想用脚本编辑plist文件就要用到命令行了,其实这是一个很简单的命令:defaults
defaults 命令的帮助如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 'defaults' [-currentHost | -host <hostname>] followed by one of the following: read shows all defaults read <domain> shows defaults for given domain read <domain> <key> shows defaults for given domain, key read-type <domain> <key> shows the type for the given domain, key write <domain> <domain_rep> writes domain (overwrites existing) write <domain> <key> <value> writes key for domain rename <domain> <old_key> <new_key> renames old_key to new_key delete <domain> deletes domain delete <domain> <key> deletes key in domain domains lists all domains find <word> lists all entries containing word help print this help <domain> is ( <domain_name> | -app <application_name> | -globalDomain ) or a path to a file omitting the '.plist' extension <value> is one of: <value_rep> -string <string_value> -data <hex_digits> -int[eger] <integer_value> -float <floating-point_value> -bool[ean] (true | false | yes | no) -date <date_rep> -array <value1> <value2> ... -array-add <value1> <value2> ... -dict <key1> <value1> <key2> <value2> ... -dict-add <key1> <value1> … </value1></key1></value2></key2></value1></key1></value2></value1></value2></value1></date_rep></floating-point_value></integer_value></hex_digits></string_value></value_rep></value></application_name></domain_name></domain></word></key></domain></domain></new_key></old_key></domain></value></key></domain></domain_rep></domain></key></domain></key></domain></domain></hostname> |
光看这些就大概知道怎么弄了吧,下面是几个例子:
1 2 3 | defaults read com.xxx.xxx // 输出文件中所有信息 defaults write com.xxx.xxx <key> <value> // 改变某个key的value,如果没有该key则添� </value></key> |
注意:在 "com.xxx.xxx" 之后没有 ".plist",开始我犯了这个错误,弄半天不知道为何plist文件中的值没有改变。
(END)