Posted on 05-18-2015 12:19 PM
Does anyone have an extension attribute for the currently logged in Mac App Store Account?
Posted on 05-19-2015 07:23 AM
I took a stab at this, and here's what I found:
~/Library/Preferences/com.apple.storeagent.plist
files.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