Created
May 21, 2016 01:10
-
-
Save ethnt/ff61ff99408cceeefac5935494eb6efc to your computer and use it in GitHub Desktop.
Ruby script to backup iMessage transcripts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pry' | |
require 'sqlite3' | |
require 'highline/import' | |
imessage_id = ask "iMessage ID (e.g., +8605555555): " | |
nickname = ask "Nickname (e.g., Bill): " | |
db = SQLite3::Database.new('/Users/ethan/Library/Messages/chat.db') | |
rows = db.execute "select * from message where handle_id=( | |
select handle_id from chat_handle_join where chat_id=( | |
select ROWID from chat where guid='iMessage;-;#{imessage_id}'))" | |
File.open("backup-#{imessage_id}.txt", 'w') do |file| | |
file.truncate(0) | |
rows.each do |row| | |
sender = if row[21] == 1 | |
"You" | |
else | |
nickname | |
end | |
time = Time.new(2001, 01, 01) + row[15] | |
text = row[2] | |
file.write("#{sender} (#{time}): #{text}\n") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment