Last active
March 30, 2018 12:00
-
-
Save scheinem/0ec42f77fd09a06988d8e890a53a5691 to your computer and use it in GitHub Desktop.
This BASH script downloads all gravatars which are available for the mail adresses stored in the macOS contacts application.
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 | |
OLD_IFS=$IFS | |
IFS=$'\n' | |
databases=( $(find ~/Library/Application\ Support/AddressBook -name "*.abcddb") ) | |
for database in ${databases[*]} | |
do | |
echo "Database: $database" | |
mailAddressesString=$(sqlite3 $database "SELECT ZADDRESS FROM ZABCDEMAILADDRESS;") | |
mailAddresses=( $mailAddressesString ) | |
for mail in ${mailAddresses[*]} | |
do | |
mailMD5=$(md5 -qs $mail) | |
image=$(curl -s "http://www.gravatar.com/avatar/${mailMD5}?d=404&s=2048" | base64) | |
OUTPUT_COLOR='' | |
if [ "${#image}" -gt 100 ] | |
then | |
mailForFileName=$( echo $mail | tr . _ ) | |
echo $image | base64 --decode > "${mailForFileName}.jpg" | |
OUTPUT_COLOR='\033[0;32m' | |
else | |
OUTPUT_COLOR='\033[0;31m' | |
fi | |
NO_COLOR='\033[0m' | |
printf "${OUTPUT_COLOR}${mail}${NO_COLOR}\n" | |
done | |
done | |
IFS=$OLD_IFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment