2

I'm trying to find on a Mac computer if the current user has iCloud Documents enabled. I found the plist where this is located (MobileMeAccounts.plist), but I could use some help with the plistbuddy syntax to target down in the tree.

Here is part of the script that I have so far:

#!/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"

I am specifically looking for the following code to be true:

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

Here is the plist. If you scroll down you'll see the "MOBILE_DOCUMENTS" with it being enabled:

<?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 Answer 1

3

You're almost there.

The trick is that you have to specify which object you want in each array. Add this index in the XML path and you're good.

To get the list of items in the array:

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

In my case MOBILE_DOCUMENTS is the first item, so it is of index 0 (second item would be index 1, third item index 2, etc).

This works for me:

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

will give "false" or "true".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .