MacOS – Export iMessages in human readable form for archival

macosmessages

I have a long (several months' worth) iMessage conversation with a contact. He lost these messages when he re-installed his OS, but I still have the archive. There is some important information there that we'd like to keep.

Is there a simple way to export this conversation for archival in a human readable form, and also keep any images?

I can select parts of the conversation, copy it to the clipboard and paste it into a rich text document, but this discards all images. I'm looking for a way that keeps the images.

Note: I use iMessage on OS X only, not iOS.

(Ideally I'd also like to export all non-image file attachments, but I'm not expecting that this will be possible.)

Best Answer

If you know the iMessage account of your contact here is a bash script of mine to retrieve text + images.

#Parameter is a iMessage account (email or phone number i.e. +33616.... )
if [ $# -lt 1 ]; then
    echo "Enter a iMessage account (email of phone number i.e +33616.....) "
fi
login=$1

#Retrieve the text messages 

sqlite3 ~/Library/Messages/chat.db "
select is_from_me,text from message where handle_id=(
select handle_id from chat_handle_join where chat_id=(
select ROWID from chat where guid='iMessage;-;$1')
)" | sed 's/1\|/me: /g;s/0\|/budy: /g' > MessageBackup.txt


#Retrieve the attached stored in the local cache

sqlite3 ~/Library/Messages/chat.db "
select filename from attachment where rowid in (
select attachment_id from message_attachment_join where message_id in (
select rowid from message where cache_has_attachments=1 and handle_id=(
select handle_id from chat_handle_join where chat_id=(
select ROWID from chat where guid='iMessage;-;$1')
)))" | cut -c 2- | awk -v home=$HOME '{print home $0}' | tr '\n' '\0' | xargs -0 -t -I fname cp fname .