如果我使用PlistBuddy修改root拥有的plist,则命令以退出代码0完成。但是,plist不会被修改。当我用sudo重新运行命令时,plist会按预期进行修改。
这是PlistBuddy中的错误吗?它在Appium configuration script中给我带来了一些麻烦。
我正在使用此命令:
/usr/libexec/PlistBuddy -c "Add :TestTestTest dict" "$SOME_PLIST_PATH" || echo "failed"
这是一个完整的会话:
tba $ echo "$SOME_PLIST_PATH"
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/Developer/Library/LaunchDaemons/com.apple.instruments.deviceservice.plist
tba $ ll "$SOME_PLIST_PATH"
-rw-r--r-- 1 root wheel 1.1K Jan 1 15:51 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/Developer/Library/LaunchDaemons/com.apple.instruments.deviceservice.plist
tba $ plutil -p "$SOME_PLIST_PATH"
{
"Program" => "/Developer/Library/PrivateFrameworks/DVTInstrumentsFoundation.framework/DTServiceHub"
"EnvironmentVariables" => {
"LIB_PATH" => "/usr/local/lib/node_modules/appium//node_modules/appium-instruments/thirdparty/iwd7/"
"DYLD_INSERT_LIBRARIES" => "/usr/local/lib/node_modules/appium//node_modules/appium-instruments/thirdparty/iwd7/DTMobileISShim.dylib"
}
"JetsamProperties" => {
"JetsamMemoryLimit" => 0
}
"POSIXSpawnType" => "Adaptive"
"MachServices" => {
"com.apple.instruments.deviceservice.xpc" => 1
"com.apple.instruments.deviceservice.lockdown" => 1
}
"EnableTransactions" => 1
"Label" => "com.apple.instruments.deviceservice"
}
tba $ /usr/libexec/PlistBuddy -c "Add :TestTestTest dict" "$SOME_PLIST_PATH" || echo "failed"
tba $ plutil -p "$SOME_PLIST_PATH"
{
"Program" => "/Developer/Library/PrivateFrameworks/DVTInstrumentsFoundation.framework/DTServiceHub"
"EnvironmentVariables" => {
"LIB_PATH" => "/usr/local/lib/node_modules/appium//node_modules/appium-instruments/thirdparty/iwd7/"
"DYLD_INSERT_LIBRARIES" => "/usr/local/lib/node_modules/appium//node_modules/appium-instruments/thirdparty/iwd7/DTMobileISShim.dylib"
}
"JetsamProperties" => {
"JetsamMemoryLimit" => 0
}
"POSIXSpawnType" => "Adaptive"
"MachServices" => {
"com.apple.instruments.deviceservice.xpc" => 1
"com.apple.instruments.deviceservice.lockdown" => 1
}
"EnableTransactions" => 1
"Label" => "com.apple.instruments.deviceservice"
}
tba $ sudo /usr/libexec/PlistBuddy -c "Add :TestTestTest dict" "$SOME_PLIST_PATH" || echo "failed"
Password:
tba $ plutil -p "$SOME_PLIST_PATH"
{
"Program" => "/Developer/Library/PrivateFrameworks/DVTInstrumentsFoundation.framework/DTServiceHub"
"EnvironmentVariables" => {
"LIB_PATH" => "/usr/local/lib/node_modules/appium//node_modules/appium-instruments/thirdparty/iwd7/"
"DYLD_INSERT_LIBRARIES" => "/usr/local/lib/node_modules/appium//node_modules/appium-instruments/thirdparty/iwd7/DTMobileISShim.dylib"
}
"JetsamProperties" => {
"JetsamMemoryLimit" => 0
}
"POSIXSpawnType" => "Adaptive"
"TestTestTest" => {
}
"MachServices" => {
"com.apple.instruments.deviceservice.xpc" => 1
"com.apple.instruments.deviceservice.lockdown" => 1
}
"EnableTransactions" => 1
"Label" => "com.apple.instruments.deviceservice"
}
答案 0 :(得分:3)
PlistBuddy没有很好的文档记录(我无法在developer.apple.com上找到它的手册页)所以很可能Apple希望使用它的高级用户(和开发人员)只是知道在弄乱root拥有的plist文件时需要调用sudo
。
我建议在bugreporter.apple.com上提交增强请求,并建议他们添加" -v
" (对于Verbose)选项PlistBuddy打印出添加或删除的结果。
现在,您只需打印出您尝试设置的设置,如果它不起作用,则设置失败。
答案 1 :(得分:1)
在我发现我没有entitlements.plist
的写入权限之前,我一直默默地失败,所以请确保您始终拥有对您正在编辑的.plist的写入权限。
另一个选择是使用plutil
,它不会无声地失败。