Last active
August 23, 2018 04:33
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Licensing, yo.