Skip to content

Instantly share code, notes, and snippets.

@smaddock
Last active March 11, 2025 16:34
Show Gist options
  • Save smaddock/628615507c96a8329de95c02cf6de9b7 to your computer and use it in GitHub Desktop.
Save smaddock/628615507c96a8329de95c02cf6de9b7 to your computer and use it in GitHub Desktop.
List Mac Internet Accounts
#!/bin/bash
# Iterate through local user accounts
for LOCAL_USER in $(dscl . list /Users UniqueID | awk '$2 >= 500 {print $1}'); do
LOCAL_HOME=$(dscacheutil -q user -a name "$LOCAL_USER" | awk -F": " '/dir/ { print $2 }')
echo "Local User: $LOCAL_USER"
# Dump iCloud Account
AA_PLIST="$LOCAL_HOME/Library/Preferences/MobileMeAccounts.plist"
if [[ -r $AA_PLIST ]]; then
echo "Found Apple Account:"
/usr/libexec/PlistBuddy -c "print :Accounts:0:AccountID" "$AA_PLIST" 2> /dev/null
fi
# Dump macOS Internet Accounts
INET_SQL="$LOCAL_HOME/Library/Accounts/Accounts4.sqlite"
if [[ -r $INET_SQL ]]; then
echo "Found macOS Internet Accounts:"
sqlite3 -json "$INET_SQL" "SELECT ZUSERNAME FROM ZACCOUNT;" 2> /dev/null \
| jq --raw-output '.[].ZUSERNAME | select(IN(null, "local") | not)'
fi
# Dump Outlook accounts, if present
OUTLOOK_PLIST="$LOCAL_HOME/Library/Group Containers/UBF8T346G9.Office/Outlook/Outlook 15 Profiles/Main Profile/ProfilePreferences.plist"
if [[ -r $OUTLOOK_PLIST ]]; then
echo "Found Microsoft Outlook Accounts:"
i=0
while /usr/libexec/PlistBuddy -c "Print :SortedAccounts:$i" "$OUTLOOK_PLIST" 2> /dev/null; do
((++i))
done
fi
# Dump Legacy Outlook accounts, if present
OUTLOOK_SQL="$LOCAL_HOME/Library/Group Containers/UBF8T346G9.Office/Outlook/Outlook 15 Profiles/Main Profile/Data/Outlook.sqlite"
if [[ -r $OUTLOOK_SQL ]]; then
echo "Found Legacy Outlook Accounts:"
sqlite3 "$OUTLOOK_SQL" "SELECT Account_EmailAddress FROM AccountsMail;" 2> /dev/null
fi
# Dump Chrome profiles, if present
CHROME_JSON="$LOCAL_HOME/Library/Application Support/Google/Chrome/Local State"
if [[ -r $CHROME_JSON ]]; then
echo "Found Chrome Profiles:"
jq --raw-output '.profile.info_cache[] | [.gaia_name, .user_name] | @tsv' "$CHROME_JSON"
fi
# Dump Edge profiles, if present
EDGE_JSON="$LOCAL_HOME/Library/Application Support/Microsoft Edge/Local State"
if [[ -r $EDGE_JSON ]]; then
echo "Found Microsoft Edge Profiles:"
jq --raw-output '.profile.info_cache[] | [.gaia_name, .user_name] | @tsv' "$EDGE_JSON"
fi
# Dump Firefox profiles, if present
FIREFOX_DIR="$LOCAL_HOME/Library/Application Support/Firefox/Profiles"
if [[ -d $FIREFOX_DIR ]]; then
echo "Found Mozilla Firefox Profiles:"
for FIREFOX_PROFILE in "$FIREFOX_DIR"/*; do
FIREFOX_JSON="$FIREFOX_PROFILE/signedInUser.json"
if [[ -r $FIREFOX_JSON ]]; then
jq --raw-output '.accountData.profileCache.profile | [.displayName, .email] | @tsv' "$FIREFOX_JSON"
fi
done
fi
echo
done
@smaddock
Copy link
Author

The macOS Internet Accounts and Outlook Accounts sections could probably be replaced with simpler osascript commands.

@smaddock
Copy link
Author

smaddock commented Mar 10, 2025

Edge/Firefox profiles could be added for completeness. Added.

@smaddock
Copy link
Author

Updated macOS Internet Accounts for current (v4) SQL schema

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