Mac Photos

From Torben's Wiki

MacOS Photos App

Interact with Python

Copy missing locations from neighboring photos

Install osxphotos

python3 -m pip install osxphotos

Update later

python3 -m pip install --upgrade osxphotos

Run in dry-run mode on selected photos

osxphotos add-locations --selected --dry-run 

Copy locations from GPX file

Install

osxphotos install gpxpy
wget https://raw.githubusercontent.com/RhetTbull/add_photo_locations_from_gpx/refs/heads/main/add_photo_locations_from_gpx.py

Run in dry-run mode on selected photos

osxphotos run add_photo_locations_from_gpx.py --selected --dry-run myFile.gpx

if time zone info is missing in photo, set UTC offset parameter like --offset +05:45:00

Extract exif data e.g. gps location

osxphotos query --selected --json | jq '.[].exif_info'

via Python and copy location to clipboard

import subprocess
import osxphotos

def copy_to_clipboard(text) -> None:
    process = subprocess.Popen(["pbcopy"], stdin=subprocess.PIPE)
    process.communicate(input=text.encode("utf-8"))

if __name__ == "__main__":
    photosdb = osxphotos.PhotosDB()
    try:
        while 1:
            results = photosdb.query(osxphotos.QueryOptions(selected=True))
            for photo in results:
                print(photo.original_filename, photo.date)
                s = f"{photo.latitude},{photo.longitude}"  # type: ignore
                print(s)
                copy_to_clipboard(s)
            input("Press Enter for next image...")
    except KeyboardInterrupt:
        pass

Links