Skip to content

Instantly share code, notes, and snippets.

@oPromessa
Created December 15, 2025 18:52
Show Gist options
  • Select an option

  • Save oPromessa/c510a6d0da8d0f52a31400dbeb9b4d6e to your computer and use it in GitHub Desktop.

Select an option

Save oPromessa/c510a6d0da8d0f52a31400dbeb9b4d6e to your computer and use it in GitHub Desktop.
osxphotos export: add to exported images keyword "person:PersonName_A" based on Photos Faces/People information
""" Custom python function as an osxphotos template filter
Use as an option to osxphotos export template in format:
"{template_field|sort|persons.py::myfilter}"
For example:
osxphotos export /path/to/export --export-by-date --exiftool --exiftool-merge-keywords --keyword-template "{keyword}" --keyword-template "{person|sort|function:persons.py::myfilter}"
The filter function will receive a list of strings even if the template renders to a single value.
You should expect a list and return a list and be able to handle multi-value templates like {keyword}
as well as single-value templates like {original_name}
"""
from typing import List
def myfilter(values: List[str]) -> List[str]:
"""Custom filter to add keywords in the format person:Person for filtered persons"""
filtered_persons = ["PersonNamed_A", "PersonNamed_B", "PersonNamed_C", "PersonNamed_D"] # Persons to include in the list
values = ["person:" + person for person in values if person in filtered_persons]
return values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment