2014-04-09 164 views
4

我的目標之一是使用defaults命令讀取屬性列表的外部構建工具。Xcode Server bot無法使用默認命令讀取屬性列表

當一個機器人運行該工具,默認命令無法找到指定的默認:

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 

運行,從一個普通用戶的帳戶相同的命令工作正常:

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

> 7.1 

但對於一些原因它不適用於_teamsserver用戶:

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 

...這是爲什麼機器人無法建立。

任何想法,爲什麼這不起作用?

謝謝。

回答

0

嘗試使用PlistBuddy代替:

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

注意,由於10.9,您不應該使用PlistBuddy修改首選項文件。 Apple增加了一個緩存系統來提高用戶首選項的性能,並且不會看到直接對首選項文件做出的更改。在這種情況下,使用「defaults」命令使用適當的API來進行首選項更改。我的猜測是,偏好緩存系統也可能是什麼導致麻煩時嘗試使用sudo「默認」命令來訪問通用plist。