Cannot access value with plistbuddy

316 Views Asked by At

I am trying to read the value of key "AccountID" from the MobileMeAccounts plist in macOS "/Library/Preferences/MobileMeAccounts.plist" and I'm getting the error:

/usr/libexec/PlistBuddy -c "print :Accounts:AccountID" /Users/username/Library/Preferences/MobileMeAccounts.plist

Error: "Print: Entry, ":Accounts:AccountID", Does Not Exist"

Here is a snippet of the output if I move up one node:

/usr/libexec/PlistBuddy -c "print :Accounts" /Users/username/Library/Preferences/MobileMeAccounts.plist

Output:

<?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>b95dc8b6-8ec4-4644-ade8-ca8e3eeb1f82</string>
            <key>AccountDSID</key>
                <string>12345678901</string>
            <key>AccountDescription</key>
                <string>iCloud</string>
            <key>AccountID</key>
                <string>[email protected]</string> * * * * * * * * * * * How do I access this value?
            <key>DisplayName</key>
                <string>firstName lastName</string>
            <key>LoggedIn</key>
                <true/>
            <key>Services</key>
            <array>

I can't seem to figure out what simple thing I'm missing in order to output "[email protected]" in this example.

1

There are 1 best solutions below

0
notarobot On

As pointed out by Gordon Davisson: "Accounts contains an array, and you need to specify which element of the array you want. Try print :Accounts:0:AccountID."