Skip to content

Instantly share code, notes, and snippets.

View RhetTbull's full-sized avatar

Rhet Turnbull RhetTbull

View GitHub Profile
@RhetTbull
RhetTbull / force_photos_download.py
Created August 30, 2020 04:50
Use osxphotos to force Photos to download missing photos from iCloud
""" use osxphotos to force the download of photos from iCloud
downloads images to a temporary directory then deletes them
resulting in the photo being downloaded to Photos library
"""
import os
import sys
import tempfile
import osxphotos
@RhetTbull
RhetTbull / sqlite2csv.py
Created September 20, 2020 15:07
Dump sqlite tables to .csv files. I found this somewhere on github and modified for my needs.
#!/usr/bin/env python3
import csv
import os.path
import sqlite3
import sys
def get_tables(cursor):
cursor.execute("select name from sqlite_master")
@RhetTbull
RhetTbull / raw2jpeg.py
Last active September 21, 2020 05:00
Convert RAW image file (or really any image CoreImage understands) to JPEG on Mac with Python
""" Convert RAW image file (or really any image CoreImage understands) to JPEG on Mac with Python """
# reference: https://stackoverflow.com/questions/59330149/coreimage-ciimage-write-jpg-is-shifting-colors-macos/59334308#59334308
import pathlib
# needed to capture system-level stderr
from wurlitzer import pipes
import Metal
import Quartz
@RhetTbull
RhetTbull / photos_text.py
Last active November 8, 2021 23:29
Extract text from images in MacOS Photos.app using tesseract OCR and update Photo description with extracted text
""" Extract text from images in Photos.app using tesseract and
update Photo description with extracted text """
# NOTE: doesn't currently work well as OCR image needs more pre-processing
# see: https://towardsdatascience.com/optical-character-recognition-ocr-with-less-than-12-lines-of-code-using-python-48404218cccb
import datetime
import pathlib
import osxphotos
@RhetTbull
RhetTbull / copy_file_with_progress_bar.py
Last active August 29, 2025 18:00
Python method to copy a file with a callback (e.g. to show a progress bar). Includes example of copying with both click.progressbar and tqdm.
""" Copy a file with callback (E.g. update a progress bar) """
# based on flutefreak7's answer at StackOverflow
# https://stackoverflow.com/questions/29967487/get-progress-back-from-shutil-file-copy-thread/48450305#48450305
# License: MIT License
import os
import pathlib
import shutil
@RhetTbull
RhetTbull / tempdiskimage.py
Last active April 10, 2022 11:10
Create and mount a temporary disk image (with auto-cleanup) on MacOS. Useful for when you need a temp file on a different file system.
""" Create and mount a temporary disk image on MacOS """
import pathlib
import platform
import subprocess
import tempfile
import time
class TempDiskImage:
@RhetTbull
RhetTbull / vision.py
Last active August 19, 2025 09:43
Use Apple's Vision framework from Python to detect text in images
""" Use Apple's Vision Framework via PyObjC to detect text in images
To use:
python3 -m pip install pyobjc-core pyobjc-framework-Quartz pyobjc-framework-Vision wurlitzer
"""
import pathlib
@RhetTbull
RhetTbull / merge_apple_photos_libraries.py
Last active January 25, 2021 02:28
Proof of concept to merge Apple Photos libraries -- still very unfinished
"""Proof of concept showing how to merge Apple Photos libraries including most of the metadata """
# Currently working:
# * places photos into correct albums and folder structure
# * sets title, description, keywords, location
# Limitations:
# * doesn't currently handle Live Photos or RAW+JPEG pairs
# * only merges the most recent version of the photo (edit history is lost)
# * very limited error handling
# * doesn't merge Person In Image
@RhetTbull
RhetTbull / adjustments.py
Created February 18, 2021 05:56
Retrieve adjustment/edit data from edited photos in Apple Photos
""" Read adjustments data for photos edited in Apple's Photos.app
In Catalina and Big Sur, the adjustments data (data about edits done to the photo)
is stored in a plist file in
~/Pictures/Photos Library.photoslibrary/resources/renders/X/UUID.plist
where X is first character of the photo's UUID string and UUID is the full UUID,
e.g.: ~/Pictures/Photos Library.photoslibrary/resources/renders/3/30362C1D-192F-4CCD-9A2A-968F436DC0DE.plist
Thanks to @neilpa who figured out how to decode this information:
Reference: https://github.com/neilpa/photohack/issues/4
"""
@RhetTbull
RhetTbull / uti.csv
Created June 28, 2021 04:10
A CSV list of Apple macOS Universal Type Identifiers (UTIs) and associated extensions & MIME types. Generated programmaticaly with calls to UTTypeCreatePreferredIdentifierForTag (https://developer.apple.com/documentation/coreservices/1448939-uttypecreatepreferredidentifierf)
extension UTI preferred_extension MIME_type
c public.c-source c None
f public.fortran-source f None
h public.c-header h None
i public.c-source.preprocessed i None
l public.lex-source l None
m public.objective-c-source m None
o public.object-code o None
r com.apple.rez-source r None
s public.assembly-source s None