Skip to content

Instantly share code, notes, and snippets.

@AndrewWCarson
Last active March 7, 2019 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AndrewWCarson/4f9ca7ef0d8ef8bb9be8d502e0ea4c61 to your computer and use it in GitHub Desktop.
Save AndrewWCarson/4f9ca7ef0d8ef8bb9be8d502e0ea4c61 to your computer and use it in GitHub Desktop.
Iterate through all login users on the device and output their Apple ID.
#!/bin/bash
# (C) Andrew Worth Carson
# MIT License: https://andrewworthcarson.com/mit_license.html
for user in $(dscl . list /Users UniqueID | awk '$2 >= 500 {print $1}'); do
userHome=$(dscl . read /Users/"$user" NFSHomeDirectory | sed 's/NFSHomeDirectory://' | grep "/" | sed 's/^[ \t]*//')
appleid=$(dscl . readpl "${userHome}" dsAttrTypeNative:LinkedIdentity appleid.apple.com:linked\ identities:0:full\ name 2> /dev/null | awk -F'full name: ' '{print $2}')
if [[ "${appleid}" == "" ]]; then
echo "No AppleID for user:${user}"
else
echo "username:${user} AppleID:${appleid}"
fi
done
@AndrewWCarson
Copy link
Author

Redirected dscl error to /dev/null to keep it clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment