Created
March 7, 2024 20:53
-
-
Save jheitzeb/1062941c26095e5e60f3bf5a42d13421 to your computer and use it in GitHub Desktop.
Export iMessages by year
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 | |
# Path to the iMessage database, adjust if necessary | |
DB_PATH=~/Library/Messages/chat.db | |
# Loop through years from 2016 to 2024 | |
for YEAR in {2016..2024} | |
do | |
echo "Exporting messages for $YEAR..." | |
sqlite3 "$DB_PATH" <<EOF | |
.output imessage-for-$YEAR.txt | |
SELECT datetime(message.date/1000000000 + strftime('%s', '2001-01-01'), 'unixepoch', 'localtime') as formatted_date, | |
CASE | |
WHEN message.is_from_me = 1 THEN 'Me' | |
ELSE 'Person-' || handle.ROWID | |
END as sender, | |
message.text as message | |
FROM message | |
LEFT JOIN handle ON message.handle_id = handle.ROWID | |
WHERE message.text IS NOT NULL AND message.text != '' AND strftime('%Y', datetime(message.date/1000000000 + strftime('%s', '2001-01-01'), 'unixepoch')) = '$YEAR' | |
ORDER BY message.date; | |
.output stdout | |
EOF | |
echo "Done exporting messages for $YEAR." | |
done | |
echo "All messages have been exported." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What this does?
A: creates files (imessage-for-2021.txt, etc) containing a yearly dump of all your iMessages