Posted on 11-15-2024 10:45 AM
I'm looking for an up to date extension attribute that checks to see if a mac has an account signed into iCloud and what that full account name is, if an account is signed in.
I've found several other EA's that look for this plist, MobileMeAccounts.plist. The mac I'm testing with is running on OS 15.1, and I do not see this plist under ~/library/preferences.
Any info on if the plist has changed or moved would be greatly appreciated as well.
Solved! Go to Solution.
Posted on 11-15-2024 11:50 AM
That PLIST should still be there. This extension attribute is working with macOS Sequoia 15.1. To be sure I just tested it in CodeRunner on my MacBook Pro running Sequoia and I see my MacBook Pro in the smart group that I setup for this EA. To further verify this, I just logged in with my iCloud account on a Mac that has a fresh install of macOS Sequoia that had not been signed in previously. The same PLIST just appeared right after I logged in.
#!/usr/bin/zsh
current_user="$(/usr/sbin/scutil <<< "show State:/Users/ConsoleUser" | /usr/bin/awk '/Name :/ && ! /loginwindow/ {print $3}')"
if [ -e "/Users/$current_user/Library/Preferences/MobileMeAccounts.plist" ]; then
icloud_account=`/usr/libexec/PlistBuddy -c "print :Accounts:0:AccountID" /Users/$current_user/Library/Preferences/MobileMeAccounts.plist`
icloud_status="Enabled by $icloud_account"
else
icloud_status="Not Enabled"
fi
echo "<result>$icloud_status</result>"
Posted on 11-15-2024 11:50 AM
That PLIST should still be there. This extension attribute is working with macOS Sequoia 15.1. To be sure I just tested it in CodeRunner on my MacBook Pro running Sequoia and I see my MacBook Pro in the smart group that I setup for this EA. To further verify this, I just logged in with my iCloud account on a Mac that has a fresh install of macOS Sequoia that had not been signed in previously. The same PLIST just appeared right after I logged in.
#!/usr/bin/zsh
current_user="$(/usr/sbin/scutil <<< "show State:/Users/ConsoleUser" | /usr/bin/awk '/Name :/ && ! /loginwindow/ {print $3}')"
if [ -e "/Users/$current_user/Library/Preferences/MobileMeAccounts.plist" ]; then
icloud_account=`/usr/libexec/PlistBuddy -c "print :Accounts:0:AccountID" /Users/$current_user/Library/Preferences/MobileMeAccounts.plist`
icloud_status="Enabled by $icloud_account"
else
icloud_status="Not Enabled"
fi
echo "<result>$icloud_status</result>"
Posted on 11-15-2024 12:46 PM
Interesting, I was signed in but didn't have that MobileMeAccounts.plist there. I had signed in probably back when it still had Ventura on it.
I signed out and signed back in and it did end up creating that plist, you're right, I'm sorry.
Posted on 11-15-2024 01:03 PM
No need to be sorry. It wouldn't be unheard of for Apple to sneak a change in under our noses. I'm curious why they still call it "MobileMeAccounts" since the service has been called iCloud since 2011.
Posted on 11-15-2024 01:48 PM
This is what I am using, and it still works as of 15.1. Looks like @howie_isaacks answered this already, but I dug the EA up so dang it I'm sharing it lol.
#!/bin/sh
## Get logged in user
UserID=$(stat -f%Su /dev/console)
iCloudAccount=$( defaults read /Users/$UserID/Library/Preferences/MobileMeAccounts.plist Accounts | grep AccountID | cut -d '"' -f 2)
if [ -z "$iCloudAccount" ]
then
echo "<result>Null</result>"
else
echo "<result>$iCloudAccount</result>"
fi
Posted on 11-15-2024 02:08 PM
Yours works just as well. This is why I love this community. Everyone is generous with their time, their knowledge, and experience.
Posted on 11-17-2024 07:20 PM
I have this one
#!/bin/bash
for user in $(ls /Users/ | grep -v -E '^(\.localized|Shared|administrator)$'); do
if [ -d "/Users/$user/Library/Application Support/iCloud/Accounts" ]; then
Accts=$(find "/Users/$user/Library/Application Support/iCloud/Accounts" | grep '@' | awk -F'/' '{print $NF}')
iCloudAccts+=(${user}: ${Accts})
else
Accts="None"
iCloudAccts+=(${user}: ${Accts})
fi
done
echo "<result>$(printf '%s
' "${iCloudAccts[@]}")</result>"
Posted on 11-18-2024 08:42 AM
This one works too. I haven't seen someone use a for loop for this before. You have just reminded me that I need to use for loops more.