PHP, Programming

Export iMessages and SMS conversations as HTML

A couple of years ago, I explained how to get instant message conversations exported out of iChat as HTML files. Now it’s 2016, and Messages has replaced iChat, and iMessages have replaced all interpersonal communication. So how do you get HTML transcripts of your iMessages and text messages? Here’s how: with my new OSX Messages Exporter script.

The script exports all of your text/iMessage conversations from Messages (including group chats) and generates HTML files for each conversation. Here’s a screenshot of the HTML file generated for a iMessage conversation between me and my brother:

Screen Shot 2016-06-20 at 10.15.35 PM

And here’s what a group conversation looks like:

Screen Shot 2016-06-20 at 10.22.55 PM

(For a look at the actual HTML, see the example.html file in the repository.)

I’ll admit that there are a number of existing solutions for exporting conversations out of Messages, but mine has some distinct advantages over them:

  1. It supports group conversations.
  2. It generates human- and machine-readable HTML.
  3. It saves all attachments.
  4. It uses contacts’ names, not just their phone numbers.
  5. I wrote it.

If you want to give it a spin, download it from GitHub and run

./messages-exporter.php --help

from the command line for the current usage instructions.

Standard

10 comments on “Export iMessages and SMS conversations as HTML

  1. ABC says:

    Hi there, I don’t know what I am doing wrong, but I get the following error:

    Fatal error: Uncaught Exception: Unable to open database: unable to open database file in /path/to/folder

    • ABC says:

      On MacOS Big Sur. I just extracted all and ran ./messages-exporter.php as I don’t need to export to a different folder, so all default settings are fine. Thanks!

      • ABC says:

        One more question! I managed to get it to work by specifying the output location using -o and the chat.db location using -d but now it doesn’t extract and include the attachments/photos in the html output files? It says [File unavailable: ~/Library/Messages/Attachments/location/here

          • ABC says:

            Thanks for the reply. Its actually like that in all the html files so it doesn’t seem an issue for old messages. I took the time to read through your readme and it said “Note that when using this option, attachments will not be saved, since the assumption is that the paths to the files are from another machine.” So I’m guessing that what happened.

            But when I try to run it with the default settings, e.g. ./messages-exporter.php -o or ./messages-exporter.php then it throws me that error: Fatal error: Uncaught Exception: Unable to open database: unable to open database file in /path/to/folder Any idea why the default settings are not working? My messages folder and chatdb is in the usual /Users/Account/Library/Messages/chat.db

            Alternatively is there a way for me to specify to include the attachments? E.g. if I have copied the entire Messages folder not just chat.db including the attachments then it could generate from there?

            • > Any idea why the default settings are not working?

              Is it possible that your $_SERVER[‘HOME’] is somehow not set to your home directory? You could test this by adding this line after line 195:

              echo $chat_db_path;

              to see what file it’s trying to open.

              > Alternatively is there a way for me to specify to include the attachments? E.g. if I have copied the entire Messages folder not just chat.db including the attachments then it could generate from there?

              Not all attachments are stored in the Messages folder, but you could change line 426 from this:

              if ( ! empty( $options[‘d’] ) ) {

              to this:

              if ( false ) {

              to just force it to try to get the attachment.

Leave a Reply

Your email address will not be published.