我已经使用 pkgbuild 创建了一个默认的组件属性列表文件。该文件看起来像:
<?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脚本修改这个文件。我尝试使用 defaults write 但它没有做任何事情。
有什么办法呢?(比如:我想把BundleIsRelocatable设置为false)
还有:
plutil -replace BundleIsRelocatable -bool false plistfilename.plist
对于字符串使用
plutil -replace NameOfProperty -string "yourNewValue" plistFileName.plist
有点晚了,但为了记录,您只需要指定绝对路径并在文件名中添加 .plist 扩展名。如果您在与 plist 文件相同的目录中运行脚本,您的案例将被翻译成:
defaults write $PWD/YourPlistFilename.plist BundleIsRelocatable -bool false
使用PlistBuddy!
非常简单直接。 例子:
/usr/libexec/PlistBuddy ComponentPropertyList.plist
Command: Set :0:BundleIsRelocatable false
Command: save
Saving...
Command: exit
就是这样!现在 BundleIsRelocatable 是 false :D
使用
sed
:
sed -i '' '/<key>BundleIsRelocatable</{n;s/true/false/;}' file.plist
如果 plist 不是 XML,先运行
plutil -convert xml1 file.plist
.
Phil-CB的最后回复这里应该有用
cli for mac 将默认为读/写。例如,我们读取 com.apple.dock.plist 并将停靠栏方向更改为左侧。
1.) 我们阅读所需的键和值,或者如果您知道,请跳至 2.)
#让你知道并阅读可以更改的可用键和值。
defaults read com.apple.dock.plist
2.) #让我们修改扩展坞
defaults write com.apple.dock orientation left
默认帮助非常有用。希望这会有所帮助 这是在 macOS 中无需添加 plistbuddy 即可执行此操作的本机方法,您只需编写脚本即可。