Skip to content

Instantly share code, notes, and snippets.

@cam8001
Forked from bgulla/imessage_dump.py
Last active August 29, 2019 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cam8001/9ce092f3343006d1409d14b214fc6af6 to your computer and use it in GitHub Desktop.
Save cam8001/9ce092f3343006d1409d14b214fc6af6 to your computer and use it in GitHub Desktop.
Dumps all images from iMessages.
import os
import pwd
import shutil
from datetime import datetime, date
username = pwd.getpwuid(os.getuid()).pw_name
rootDir = "/Users/{}/Library/Messages/Attachments".format(username)
destDir = "/Users/{}/Desktop/imessage_dump".format(username)
IGNORE_STRING = "pluginPayloadAttachment"
for dirName, subdirList, fileList in os.walk(rootDir):
#print("Found directory: %s" % dirName)
for fname in fileList:
if IGNORE_STRING in fname:
print("skipping: \t%s" % fname)
continue
src_fp = os.path.join(rootDir, dirName,fname)
mtime = os.path.getmtime(src_fp)
datetime = datetime.fromtimestamp(mtime)
# Size in bytes
size = os.path.getsize(src_fp)
print("{} {} {} kB".format(datetime.strftime('%Y-%m-%d %H:%M'), fname, size >> 10))
src_fp = os.path.join(rootDir, dirName,fname)
dest_fp = os.path.join(destDir, fname)
shutil.copy2(src_fp, dest_fp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment