Skip to content

Instantly share code, notes, and snippets.

@AndrewWCarson
Last active August 23, 2018 04:33
Show Gist options
  • Select an option

  • Save AndrewWCarson/888d9b539b07e09fa31ee04fd815ba8d to your computer and use it in GitHub Desktop.

Select an option

Save AndrewWCarson/888d9b539b07e09fa31ee04fd815ba8d to your computer and use it in GitHub Desktop.
Grabs the currently logged in user and checks to see if they have an associated AppleID.
#!/bin/bash
# (C) Andrew Worth Carson
# MIT License: https://andrewworthcarson.com/mit_license.html
username=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");')
if [[ "${username}" == "" ]]; then
echo "No user currently logged in."
exit 1
else
appleid=$(! dscl . readpl "/Users/${username}" dsAttrTypeNative:LinkedIdentity appleid.apple.com:linked\ identities:0:full\ name | awk -F'full name: ' '{print $2}')
if [[ "${appleid}" == "" ]]; then
echo "AppleID was not found."
exit 2
else
echo "${appleid}"
exit 0
fi
fi
@AndrewWCarson
Copy link
Copy Markdown
Author

Licensing, yo.

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