macos - PlistBuddy 默默地失败了——bug?

标签 macos plist

如果我使用 PlistBuddy 修改 root 拥有的 plist,该命令会以退出代码 0 完成。但是,plist 不会被修改。当我使用 sudo 重新运行该命令时,plist 会按预期进行修改。

这是 PlistBuddy 中的错误吗?这给我带来了一些麻烦 Appium configuration script .


我正在使用这个命令:

/usr/libexec/PlistBuddy -c "Add :TestTestTest dict" "$SOME_PLIST_PATH" || echo "failed"

这是完整的 session :

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"
}

最佳答案

PlistBuddy 没有很好的文档记录(我在developer.apple.com 上找不到它的手册页),因此 Apple 很可能希望使用它的高级用户(和开发人员)简单地知道 sudo当弄乱 root 拥有的 plist 文件时需要调用。

我建议在 bugreporter.apple.com 上提交增强请求,并建议他们向 PlistBuddy 添加“-v”(用于详细)选项,以打印添加或删除的结果。

目前,您所能做的就是打印出您尝试设置的设置,如果不起作用,则设置失败。

关于macos - PlistBuddy 默默地失败了——bug?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34561340/

相关文章:

ios - 将嵌套类写入 plist

IOS 使用 NSKeyedArchiver 保存关联数组

macos - NSTableView:当 float subview 被删除时收到通知

macos - 使 OSX-Service 在 Apple Automator 中批量重命名(将自定义文本 append 到文件名)

iphone - 如何管理静态、延迟加载的字典和数组的内存负载

swift - 从 Info.plist 中删除没有数据的键

iOS 从 .plist 文件加载数据

c++ - 如何确定二进制文件是否在 Mac OS X 上被剥离?

ios - 无法从此设备复制符号

python - 在 MacOS(Apple/Mac)上安装 Conda 的最佳方法是什么?