Skip to main content
added 40 characters in body
Source Link
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 orof 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 .

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 or phone number i.e +33616.....) "
fi
login=$1

#Retrieve the text messages 
    
sqlite3 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 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 .

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 .
added 481 characters in body
Source Link
Matthieu Riegler
  • 21.8k
  • 11
  • 62
  • 98

If you know the iMessage account of your contact you can do following :

sqlite3 chat.db "select * from message where handle_id=((select ROWID from chat where guid='iMessage;-;+#########')-1)" | awk 'BEGIN { FS = "|"; } ; {print $17 " " $3}' | sed 's/^0/me :/g' | sed 's/^[0-9][0-9]*/him :/g'

Replace the ##### by the iMessage account. In my case ithere is +33616.... (yes with the prefix)


Explanation of the oneliner :a bash script of mine to retrieve text + images.

  1. We need the handle_id of your contact in the DB.
  2. The id has to be decremented
  3. With the ID we can retrieve all the text in the DB
  4. awk is just here to parse the message and who wrote that
  5. sedis just here to replace the number retrieved by awk that do mean that much and replace them with "me" and "him".
#Parameter is a iMessage account (email or phone number i.e. +33616.... )
if [ $# -lt 1 ]; then
    echo "Enter a iMessage account (email or phone number i.e +33616.....) "
fi
login=$1

#Retrieve the text messages 
    
sqlite3 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 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 .

If you know the iMessage account of your contact you can do following :

sqlite3 chat.db "select * from message where handle_id=((select ROWID from chat where guid='iMessage;-;+#########')-1)" | awk 'BEGIN { FS = "|"; } ; {print $17 " " $3}' | sed 's/^0/me :/g' | sed 's/^[0-9][0-9]*/him :/g'

Replace the ##### by the iMessage account. In my case it is +33616.... (yes with the prefix)


Explanation of the oneliner :

  1. We need the handle_id of your contact in the DB.
  2. The id has to be decremented
  3. With the ID we can retrieve all the text in the DB
  4. awk is just here to parse the message and who wrote that
  5. sedis just here to replace the number retrieved by awk that do mean that much and replace them with "me" and "him".

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 or phone number i.e +33616.....) "
fi
login=$1

#Retrieve the text messages 
    
sqlite3 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 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 .
deleted 31 characters in body
Source Link
Matthieu Riegler
  • 21.8k
  • 11
  • 62
  • 98

If you know the iMessage account of your contact you can do following :

sqlite3 chat.db "select * from message where handle_id=((select ROWID from chat where guid="iMessage;guid='iMessage;-;+#########";+#########')-1) order by rowid desc limit 10;"" | awk 'BEGIN { FS = "|"; } ; {print $17 " " $3}' | sed 's/^0/me :/g' | sed 's/^[0-9][0-9]*/him :/g'

Replace the ##### by the iMessage account. In my case it is +33616.... (yes with the prefix)


Explanation of the oneliner :

  1. We need the handle_id of your contact in the DB.
  2. The id has to be decremented
  3. With the ID we can retrieve all the text in the DB
  4. awk is just here to parse the message and who wrote that
  5. sedis just here to replace the number retrieved by awk that do mean that much and replace them with "me" and "him".

If you know the iMessage account of your contact you can do following :

sqlite3 chat.db "select * from message where handle_id=(select ROWID from chat where guid="iMessage;-;+#########")-1) order by rowid desc limit 10;" | awk 'BEGIN { FS = "|"; } ; {print $17 " " $3}' | sed 's/^0/me :/g' | sed 's/^[0-9][0-9]*/him :/g'

Replace the ##### by the iMessage account. In my case it is +33616.... (yes with the prefix)


Explanation of the oneliner :

  1. We need the handle_id of your contact in the DB.
  2. The id has to be decremented
  3. With the ID we can retrieve all the text in the DB
  4. awk is just here to parse the message and who wrote that
  5. sedis just here to replace the number retrieved by awk that do mean that much and replace them with "me" and "him".

If you know the iMessage account of your contact you can do following :

sqlite3 chat.db "select * from message where handle_id=((select ROWID from chat where guid='iMessage;-;+#########')-1)" | awk 'BEGIN { FS = "|"; } ; {print $17 " " $3}' | sed 's/^0/me :/g' | sed 's/^[0-9][0-9]*/him :/g'

Replace the ##### by the iMessage account. In my case it is +33616.... (yes with the prefix)


Explanation of the oneliner :

  1. We need the handle_id of your contact in the DB.
  2. The id has to be decremented
  3. With the ID we can retrieve all the text in the DB
  4. awk is just here to parse the message and who wrote that
  5. sedis just here to replace the number retrieved by awk that do mean that much and replace them with "me" and "him".
added 73 characters in body
Source Link
Matthieu Riegler
  • 21.8k
  • 11
  • 62
  • 98
Loading
Source Link
Matthieu Riegler
  • 21.8k
  • 11
  • 62
  • 98
Loading