2014-10-05 192 views
13

我已经使用pkgbuild创建默认的组件属性列表文件。该文件看起来像:使用shell脚本编辑plist文件

<?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"> 
<array> 
    <dict> 
     <key>BundleHasStrictIdentifier</key> 
     <true/> 
     <key>BundleIsRelocatable</key> 
     <true/> 
     <key>BundleIsVersionChecked</key> 
     <true/> 
     <key>BundleOverwriteAction</key> 
     <string>upgrade</string> 
     <key>RootRelativeBundlePath</key> 
     <string>MyApp.app</string> 
    </dict> 
</array> 
</plist> 

我想通过使用shell脚本来修改此文件。我尝试使用默认写入但它没有做任何事情。

什么是做到这一点?(例如:我想BundleIsRelocatable设置为false)

回答

21

另外:

plutil -replace BundleIsRelocatable -bool false plistfilename.plist 
2

使用PlistBuddy

非常简单直接。 例如:

/usr/libexec/PlistBuddy ComponentPropertyList.plist 
Command: Set :0:BundleIsRelocatable false 
Command: save 
Saving... 
Command: exit 

那就是它!现在BundleIsRelocatable是假的:d

-1

使用sed

sed -i '' '/<key>BundleIsRelocatable</{n;s/true/false/;}' file.plist 

如果plist中没有XML,运行plutil -convert xml1 file.plist第一。

0

Phil-CB here的最后响应应该是有用的。

0

字符串使用

plutil -replace NameOfProperty -string "yourNewValue" plistFileName.plist 
1

有点晚了,但备案,你只需要到指定的绝对路径和的.plist扩展添加到文件名。如果您在脚本文件的同一目录中运行脚本,则会将您的案例翻译为:

defaults write $PWD/YourPlistFilename.plist BundleIsRelocatable -bool false