Skip to main content
5 of 5
added 40 characters in body
Matthieu Riegler
  • 21.8k
  • 11
  • 62
  • 98

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 .
Matthieu Riegler
  • 21.8k
  • 11
  • 62
  • 98