If I use PlistBuddy to modify a plist owned by root, the command completes with exit code 0. However, the plist is not modified. When I re-run the command with sudo, the plist is modified as expected.
Is this a bug in PlistBuddy? It caused me some trouble in an Appium configuration script.
I'm using this command:
/usr/libexec/PlistBuddy -c "Add :TestTestTest dict" "$SOME_PLIST_PATH" || echo "failed"
Here is a full 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 isn't very well documented (I can't find a man page for it on developer.apple.com) so it may well be that Apple expects power users (and developers) who use it to simply know that sudo
needs to be invoked when messing with a root-owned plist file.
I'd recommend filing an enhancement request at bugreporter.apple.com and suggest they add a "-v
" (for Verbose) option to PlistBuddy to print out results from adding or removing.
For now, all you can do it print out the setting you attempted to set and if it didn't work, the setting therefore failed.