Mac OS 下命令行编辑plist的方法

来源:互联网 发布:淘宝上找不到的衣服 编辑:程序博客网 时间:2024/05/21 20:28

    一般我们编辑plist文件都是直接打开,用PlistEditor什么的进行可视化编辑,但是如果想用脚本编辑plist文件就要用到命令行了,其实这是一个很简单的命令:defaults

    defaults 命令的帮助如下

12345678910111213141516171819202122232425262728293031323334353637
&#39;defaults&#39; [-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 &#39;.plist&#39; 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> &hellip;</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>

 

    光看这些就大概知道怎么弄了吧,下面是几个例子:

123
defaults read com.xxx.xxx // 输出文件中所有信息defaults write com.xxx.xxx <key> <value> // 改变某个key的value,如果没有该key则添�</value></key>

 

    注意:在 "com.xxx.xxx" 之后没有 ".plist",开始我犯了这个错误,弄半天不知道为何plist文件中的值没有改变。

   (END)

0 0