Package: photoscript
PhotoScriptWhat is PhotoScriptPhotoScript provides a python wrapper around Apple Photos applescript interface.  With PhotoScript you can interact with Photos using python.  Runs only on MacOS.  Tested on MacOS Catalina.PhotosScript is limited by Photos' very limited AppleScript dictionary.CompatibilityDesigned for MacOS Catalina/Photos 5.  Preliminary testing on Big Sur/Photos 6 beta shows this should work on Big Sur as well.  Photos' AppleScript interface has changed very little since Photos 2 (the earliest version I have access to).  This package should work with most versions of Photos but some methods may not function correctly on versions earlier than Photos 5.  If you find compatibility issues, open an issue or send a PR.InstallationPhotoScript usespoetryfor dependency management.  To install, clone the repo and runpoetry install. If you don't have poetry already installed, follow theinstallation instructions. To enter the virtual environment, runpoetry shell.Or you can install via pip:python3 -m pip install photoscriptExample""" Simple example showing use of photoscript """importphotoscriptphotoslib=photoscript.PhotosLibrary()photoslib.activate()print(f"Running Photos version:{photoslib.version}")album=photoslib.album("Album1")photos=album.photos()forphotoinphotos:photo.keywords=["travel","vacation"]print(f"{photo.title},{photo.description},{photo.keywords}")new_album=photoslib.create_album("New Album")photoslib.import_photos(["/Users/rhet/Downloads/test.jpeg"],album=new_album)photoslib.quit()DocumentationFull documentationhere.Additional documentation about Photos and AppleScript available on thewiki.TestingTested on MacOS Catalina, Photos 5 with 100% coverage.LimitationsPhotos' AppleScript interface is very limited.  For example, it cannot access information on faces in photos nor can it delete a photo.  PhotoScript is thus limited.  PhotoScript works by executing AppleScript through an Objective-C bridge from python.  Every method call has to do a python->Objective C->AppleScript round trip; this makes the interface much slower than native python code.  This is particularly noticeable when dealing with Folders which requires significant work arounds.Where possible, PhotoScript attempts to provide work-arounds to Photos' limitations. For example, Photos does not provide a way to remove a photo from an album.  PhotoScript does provide aAlbum.remove()method but in order to do this, it creates a new album with the same name as the original, copies all but the removed photos to the new album then deletes the original album.  This simulates removing photos and produces the desired effect but is not the same thing as removing a photo from an album.Related Projectsosxphotos: Python package that provides read-only access to the Photos library including all associated metadata.Dependenciespy-applescriptPyObjCContributors ✨Thanks goes to these wonderful people (emoji key):David Haberthür📖André Anjos🤔🐛This project follows theall-contributorsspecification. Contributions of any kind welcome!See AlsoFor a more comprehensive python interface for Mac automation, seePyXAwhich provides a python interface to Photos and many other Mac applications.