Friday, February 25, 2022

OSXPhotos Python Tool

Rhet Turnbull (via Stephan Arlt):

OSXPhotos provides the ability to interact with and query Apple’s Photos.app library on macOS. You can query the Photos library database — for example, file name, file path, and metadata such as keywords/tags, persons/faces, albums, etc. You can also easily export both the original and edited photos.

[…]

If you encounter missing photos you can tell osxphotos to download the missing photos from iCloud using the --download-missing option. --download-missing uses AppleScript to communicate with Photos and tell it to download the missing photos. Photos’ AppleScript interface is somewhat buggy and you may find that Photos crashes. In this case, osxphotos will attempt to restart Photos to resume the download process. There’s also an experimental --use-photokit option that will communicate with Photos using a different “PhotoKit” interface. This option must be used together with --download-missing[…]

[…]

Photos tracks a tremendous amount of metadata associated with photos in the library such as keywords, faces and persons, reverse geolocation data, and image classification labels. Photos’ native export capability does not preserve most of this metadata. osxphotos can, however, access and preserve almost all the metadata associated with photos.

This uses SQLite and reverse engineering rather than the more limited PhotoKit.

6 Comments RSS · Twitter

I'm the author of this python package -- thanks for the shout out! It would be really nice if Apple provided an API to access all your Photos metadata. I think that's unlikely to happen so osxphotos had to use reverse engineering as you've noted. For anyone else wanting to poke around the Photos database, much of what I've figured out is documented in the osxphotos wiki: https://github.com/RhetTbull/osxphotos/wiki

This looks really great! I've been using Photos (and previously iPhoto) for years. I think in Big Sur Photos.app started to save originals using randomly named files and folders (something like UUID) inside the Library package. That was a little troubling for me, because it makes switching to another photo manager app harder. This tool seems to be able to preserve the original filenames when exporting.

> I think in Big Sur Photos.app started to save originals using randomly named files and folders (something like UUID) inside the Library package. That was a little troubling for me, because it makes switching to another photo manager app harder. This tool seems to be able to preserve the original filenames when exporting.

@Dan yes, osxphotos can preserve the original filenames. The switch actually happened in Catalina which included a major rewrite of Photos.app with an entirely new database schema. As you've noted, photos are now renamed with a UUID naming scheme when importing to Photos. With osxphotos, you can easily export with the original filename using something like this:

osxphotos export /path/to/export --filename "{original_name}" --directory "{created.year}/{created.mm}/{created.dd}"

This uses a template to rename files with the original filename and creates directories based on photo creation date in format 'YYYY/MM/DD'

Hello,
I used the osxphotos command line tool heavily. It is the highlander with Apple fotos database (it is great and the only one) but I have encountered some issues as well. I'd be interested if you know that experience and may have a solution to it.

First,
I felt that for long commands with many options the order is important. An option at one place may not work but at another place does.
Second,
using the "iterm" app which allows to save code snippets. When I save the code snippet I may or may not run. osxphotos says that the command or option was not recognized. Need to retype manually.
Third and my most urgent challenge at the moment,
I cannot get the "diff command" running. I created two test foto databases, one with three fotos and one with the same three and one additional fotos. I'd had expected to see that outcome. However, when I run the command "osxphotos diff --db /Users//Pictures/Test-FotosDB/Test2.photoslibrary /Users//Pictures/Test-FotosDB/Test1.photoslibrary" the osxphotos app throws an exception "IndexError: list index out of range". Do you know if I did something wrong?

Hello Frank. I'm the author of osxphotos. I'm glad you find the tool useful! Please post your questions over at the osxphotos discussion page at https://github.com/RhetTbull/osxphotos/discussions as it will be much easier to answer them there. I've taken the liberty of starting a discussion and providing answers at: https://github.com/RhetTbull/osxphotos/discussions/668

Hi Rhet,

much appreciated your prompt reply and that you started the discussion thread. As yourself - if I read the information provided correctly you are doing all this excellent stuff in your free-time - I am quite busy at the moment earning my daily bread, so it may take me some time to reply but I will.

Best regards
Frank

Leave a Comment