Eintrag in plist mit PlistBuddy (osx) finden

1104
Dan

Ich versuche auf einem Mac-Computer herauszufinden, ob der aktuelle Benutzer iCloud Documents aktiviert hat. Ich habe die Plist-Datei gefunden, an der sich diese befindet (MobileMeAccounts.plist), aber ich könnte etwas Hilfe mit der Plistbuddy-Syntax verwenden, um in der Baumstruktur ein Ziel festzulegen.

Hier ist ein Teil des Skripts, das ich bisher habe:

#!/bin/bash  # Purpose: Grab iCloud Document Status  plistBud="/usr/libexec/PlistBuddy"  if [[ -e "/Users/*loggedInUser*/Library/Preferences/MobileMeAccounts.plist" ]]; then  iCloudStatus=`$plistBud -c "print :Accounts:Services:MOBILE_DOCUMENTS" /Users/$loggedInUser/Library/Preferences/MobileMeAccounts.plist` else  iCloudDocuments="Not Enabled"  fi  echo "$iCloudStatus" 

Ich suche speziell den folgenden Code, um wahr zu sein:

<key>Enabled</key> <true/> 

Hier ist der Plist. Wenn Sie nach unten scrollen, wird "MOBILE_DOCUMENTS" angezeigt, wenn es aktiviert ist:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Accounts</key> <array> <dict> <key>AccountAlternateDSID</key> <string>99999999</string> <key>AccountDSID</key> <string>999999</string> <key>AccountDescription</key> <string>iCloud</string> <key>AccountID</key> <string>*****@gmail.com</string> <key>AccountUUID</key> <string>9999999</string> <key>DisplayName</key> <string>User Name</string> <key>LoggedIn</key> <true/> <key>Services</key> <array> <dict> <key>Name</key> <string>CLOUDDESKTOP</string> <key>ServiceID</key> <string>com.apple.Dataclass.CloudDesktop</string> <key>status</key> <string>active</string> </dict> <dict> <key>Name</key> <string>FAMILY</string> <key>ServiceID</key> <string>com.apple.Dataclass.Family</string> <key>showManageFamily</key> <true/> </dict> <dict> <key>Enabled</key> <true/> <key>Name</key> <string>MOBILE_DOCUMENTS</string> <key>ServiceID</key> <string>com.apple.Dataclass.Ubiquity</string> <key>apsEnv</key> <string>production</string> <key>authMechanism</key> <string>token</string> <key>url</key> <string>https://p48-ubiquity.icloud.com:443</string> <key>wsUrl</key> <string>https://p48-ubiquityws.icloud.com:443</string> </dict> 
1

1 Antwort auf die Frage

0
Moritz

Du bist fast da.

Der Trick ist, dass Sie angeben müssen, welches Objekt Sie in jedem Array verwenden möchten. Fügen Sie diesen Index in den XML-Pfad ein und Sie sind in Ordnung.

So rufen Sie die Liste der Elemente im Array ab:

/usr/libexec/PlistBuddy -c "print :Accounts:0:Services" ~/Library/Preferences/MobileMeAccounts.plist 

In meinem Fall MOBILE_DOCUMENTSist das erste Element der Index 0 (das zweite Element wäre Index 1, das dritte Element Index 2 usw.).

Das funktioniert für mich:

/usr/libexec/PlistBuddy -c "print :Accounts:0:Services:0:Enabled" ~/Library/Preferences/MobileMeAccounts.plist 

wird "falsch" oder "wahr" geben.