Does anyone have an extension attribute for the currently logged in Mac App Store Account?
I took a stab at this, and here's what I found:
- Each user account in OS X has its own plist file that stores the information on registered App Store accounts. These are stored in
~/Library/Preferences/com.apple.storeagent.plist
files. - There is an array in the plist (called KnownAccounts) with a dictionary within it that holds basic account details, and whether that account is "Signed In".
- I'm not certain, but I believe if a single OS X account had multiple different users signed into the MAS under different accounts at different times, there would probably be multiple dict's within the array - one for each account that has registered with the App Store.
- Oddly, even after I logged out of my Mac App Store account in the App Store.app, the plist file still shows that my account is "Signed In" This leads me to believe that it doesn't get updated until another MAS account is signed into within the app. Basically, that value seems to show either the current signed in or last signed in account, but not actually if its still signed in right now.
The scenario from point 3 seems a bit unlikely, unless you're talking about a shared lab computer where users can sign in and out of the Mac App Store under the same generic "lab" account or something. Generally speaking I'd think most OS X accounts would only have a single dict within the KnownAccounts array, for the primary user of the system.
Given this, I came up with the following EA. Keep in mind this would only get info from the first dictionary in the array. If there happen to be multiple ones, its not looping over them, though I suppose it could be made to do that.
Also, as per point 4, just because it reports an account as the "Signed In" account, doesn't mean it actually is, just that it was the last signed in account and might still be signed in.
#!/bin/bash
while read acct; do
userHome=$(dscl . read /Users/$acct NFSHomeDirectory | awk '{print $NF}')
if [ -e "${userHome}/Library/Preferences/com.apple.storeagent.plist" ]; then
AppleID=$(/usr/libexec/PlistBuddy -c "Print :KnownAccounts:0:AppleID" "${userHome}/Library/Preferences/com.apple.storeagent.plist" 2>/dev/null)
SignedIn=$(/usr/libexec/PlistBuddy -c "Print :KnownAccounts:0:SignedIn" "${userHome}/Library/Preferences/com.apple.storeagent.plist" 2>/dev/null)
if [ "$SignedIn" == "true" ]; then
SignedInID+=("User: ${acct}, ID: ${AppleID}")
fi
fi
done < <(dscl . list /Users UniqueID | awk '$2>500 {print $1}')
if [ "${SignedInID[@]}" != "" ]; then
echo "<result>$(printf '%s
' "${SignedInID[@]}")</result>"
else
echo "<result>No ID logged in</result>"
fi
Output will look something like this-
User: mike, ID: mm2270@mac.com
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.