Skip to content

Instantly share code, notes, and snippets.

@jxmorris12
Created April 5, 2019 13:01
Show Gist options
  • Save jxmorris12/ad8ef9675b43280b9124ff5bd5708785 to your computer and use it in GitHub Desktop.
Save jxmorris12/ad8ef9675b43280b9124ff5bd5708785 to your computer and use it in GitHub Desktop.
Copy all pictures from iMessage on Mac to current folder
# needs python 3.5+
import glob
import os
def sh_escape(s):
return s.replace("(", "\\(").replace(")","\\)").replace(" ","\\ ")
home = '/Users/myusername'
glob_path = home + '/Library/Messages/Attachments/**/*'
files = []
for ext in ['png', 'jpeg', 'jpg']:
print(glob_path + ext)
files.extend(glob.glob(glob_path + ext, recursive=True))
EXT = ext.upper()
files.extend(glob.glob(glob_path + EXT, recursive=True))
for filename in files:
cmd = 'cp -p {} .'.format(sh_escape(filename))
os.system(cmd)
@jxmorris12
Copy link
Author

iMessage stores all images in subfolders of ~/Messages/Attachments. It's not meant to be user-facing, but it can be. I ran this script to back up all my images from past text messages before wiping my laptop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment