Programmatically importing pictures to Apple Photos and modifying Exif data

910 views Asked by At

How do I programmatically import picture files to Apple's Photos app?

The reason for this is that I have 20,000 old pictures. Most are in folders whose names have the data of when the pictures were taken or the file names themselves have the date and time stamps. So the idea is to import the pictures into Photos, but setting the folder/file name as the date and time taken.

Any hints? Thanks! Oh, and I'm doing this in Python.

If I have to move this to SuperUser, please let me know.

2

There are 2 answers

1
bskp On

Late to the party, but I faced the problem myself and solved it as follows:

open /System/Applications/Photos.app --args foo.jpeg bar.jpeg

Two caveats:

  • When passing one image alone, it is imported immediately.
    With multiple images, however, the import-UI is shown, where the user will have to confirm the import.

  • If Photos.app is running already, it is brought to the foreground without triggering any imports. If acceptable, it can be force-quit beforehand:

    killall Photos

In the context of Python, system calls can be done using

import os
os.system('open /System/Applications/Photos.app --args foo.jpeg')

This was just the importing step. For mangling with the metadata, pyexiv2 is a fantastic library.

See also:

0
Andrew Summer On

open /System/Applications/Photos.app --args foo.jpeg bar.jpeg

Does not work on MacOS 14. It just opens the Photos App, nothing is imported.

One could use osxphotos for the task at hand.

See: https://rhettbull.github.io/osxphotos/overview.html

It did not install via pipx in my tests on MacOS 14 though. But it still sounds like the perfect tool.

v0.60.8 seems to add MacOS Sonoma Support: https://github.com/RhetTbull/osxphotos/releases/tag/v0.60.8