I am doing some archiving after a loss and would like to preserve a chat thread with one person in plaid text/pdf (not .HTML by date). The thread goes back 2.5years, so there is a lot. I have accessed the ~/Library/Messages folder but there is no good way to get the thread/messages into a format where i can make one large file of all of them. Any ideas?
2 Answers
The Messages app stores history in ~/Library/Messages/chat.db
, which is a database in SQLite format. To open it and inspect it, you'll need to install the SQLite tools, which are available from the SQLite website or from Homebrew with brew install sqlite
.
In a terminal, run sqlite3 ~/Library/Messages/chat.db
, which will open the sqlite3 command line. Type SELECT * FROM handle;
and search for the relevant conversation - its ID is the number in the first column.
Next, run .output filename.txt
to set a path for the output to be saved, and
then run the following command, replacing 12345 with the ID of the conversation you're exporting.
SELECT handle_id, date, datetime(date / 1000000000,'unixepoch','31 years'), text
FROM message T1
INNER JOIN chat_message_join T2
ON T2.chat_id=12345
AND T1.ROWID=T2.message_id
ORDER BY T1.date;
You will now have a text file, filename.txt
, containing this conversation in chronological order. You can run .schema message
to see the full list of columns if you would like to save more data - simply add a comma and the name of the column onto the SELECT statement.
-
-
See my edit - I've explained how to export some other message information.– quartzicFeb 20, 2021 at 0:58
-
Got it! Thanks to a couple of stack overflow answers. My first line is now SELECT handle_id, date, datetime(date / 1000000000,'unixepoch','31 years'), text Apple date/time is unix-like dates but from 1 Jan 2001 and since Mojave(?) are in nanoseconds. I will leave you to modify your answer - I have already upvoted.– GilbyFeb 20, 2021 at 3:02
Another option is the app iExplorer which can extract an entire Messages conversation from first to last message, including images, into a PDF file. I believe they still have a free trial available so you can see if it works for you. It is also a very powerful tool for working on iOS devices outside of the limited Apple app access.
Disclaimer: I'm a satisfied user of iExplorer both personally and professionally, and have no financial or other interests in Macroplant LLC.