Skip to main content

Python wrapper around Apple Photos applescript interface

Project description

PhotoScript

Code style: black License: MIT

All Contributors

What is PhotoScript

PhotoScript 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.

Compatibility

Designed 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.

Installation

You can install via pip:

python3 -m pip install photoscript

To install via the source code:

  • Install uv if not already installed
  • Clone the repo: git clone git@github.com:RhetTbull/PhotoScript.git
  • Change to the directory: cd PhotoScript
  • Run uv pip install -r pyproject.toml.

If you want to develop code for PhotoScript, see README_DEV.md.

Example

""" Simple example showing use of photoscript """

import photoscript

photoslib = photoscript.PhotosLibrary()

photoslib.activate()
print(f"Running Photos version: {photoslib.version}")

album = photoslib.album("Album1")
photos = album.photos()

for photo in photos:
    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()

Documentation

Full documentation here.

Additional documentation about Photos and AppleScript available on the wiki.

Testing

Tested on MacOS Catalina, Photos 5 with 100% coverage.

Limitations

Photos' 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 a Album.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 Projects

  • osxphotos: Python package that provides read-only access to the Photos library including all associated metadata.
  • PhotoKit: Experimental Python package for accessing the macOS Photos.app library via Apple's native PhotoKit framework.

Dependencies

Contributors ✨

Thanks goes to these wonderful people (emoji key):

David Haberthür
David Haberthür

📖
André Anjos
André Anjos

🤔 🐛
oPromessa
oPromessa

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

See Also

For a more comprehensive python interface for Mac automation, see PyXA which provides a python interface to Photos and many other Mac applications.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

photoscript-0.5.3.tar.gz (29.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

photoscript-0.5.3-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file photoscript-0.5.3.tar.gz.

File metadata

  • Download URL: photoscript-0.5.3.tar.gz
  • Upload date:
  • Size: 29.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for photoscript-0.5.3.tar.gz
Algorithm Hash digest
SHA256 4d54bb99866f2450903be9f4996f311097d816e26dfae55c541f2ef58fc745dd
MD5 435cc610ee352b97b8d8b8d102add5b0
BLAKE2b-256 b9b855ef5e2285c8effe52d48ca053672b4a25bdc5c96e4666d187fa7deb95d3

See more details on using hashes here.

File details

Details for the file photoscript-0.5.3-py3-none-any.whl.

File metadata

File hashes

Hashes for photoscript-0.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4e4dba3ece23e0fba4ea6aa30c29526f3e9097182006a38011c61c44afefc4bf
MD5 336e8f2683a743a59f21ca1b52c16d02
BLAKE2b-256 22a7a0559b8b1ec72bddba078b96b37f2ca71c61d1845d53babd1f58c09deb51

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page