5

One of my targets is an external build tool that uses the defaults command to read a property list.

When a bot runs that tool, the defaults command fails to find the specified default:

defaults read /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/version CFBundleShortVersionString

> The domain/default pair of (/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/version, CFBundleShortVersionString) does not exist

Running that same command from a regular user's account works fine:

defaults read /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/version CFBundleShortVersionString

> 7.1

But for some reason it doesn't work for the _teamsserver user:

sudo -u _teamsserver defaults read /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/version CFBundleShortVersionString

> The domain/default pair of (/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/version, CFBundleShortVersionString) does not exist

…which is why the bot can't build.

Any idea why this doesn't work?

Thanks.

Mike Greiner
  • 306
  • 1
  • 7

1 Answers1

0

Try using PlistBuddy instead:

/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/version.plist

Note that since 10.9, you should NOT use PlistBuddy for modifying preference files. Apple added a caching system to improve the performance of user preferences and it won't see changes made directly to preferences files. In that case, use the "defaults" command which uses the proper API to make preferences changes. My guess is that the preferences caching system may also be what's causing trouble when trying to use the "defaults" command with sudo to access a generic plist.

js2
  • 16
  • 1