Photos Module Reference
New in version 0.0.2.
Control the macOS Photos application using JXA-like syntax.
Todo
Add support for folders and containers
Add image operations such as rotate, flip
Add ability to add new albums
Add ability to move photos to albums/folders
Classes:
|
An album in Photos.app. |
|
A wrapper around lists of albums that employs fast enumeration techniques. |
|
A class for managing and interacting with Photos.app. |
|
A class for... |
|
A wrapper around lists of containers that employs fast enumeration techniques. |
|
A folder in Photos.app. |
|
A wrapper around lists of folders that employs fast enumeration techniques. |
|
A photo or video in Photos.app. |
|
A wrapper around lists of media items that employs fast enumeration techniques. |
- class PyXA.apps.PhotosApp.XAPhotosAlbum(properties)[source]
Bases:
XAPhotosContainer
An album in Photos.app.
New in version 0.0.2.
Methods:
media_items
([filter])Returns a list of media items, as PyXA objects, matching the given filter.
- media_items(filter: dict | None = None) XAPhotosMediaItemList [source]
Returns a list of media items, as PyXA objects, matching the given filter.
- Parameters:
filter (Union[dict, None]) – A dictionary specifying property-value pairs that all returned media items will have, or None
- Returns:
The list of media items
- Return type:
New in version 0.0.6.
- class PyXA.apps.PhotosApp.XAPhotosAlbumList(properties: dict, filter: dict | None = None)[source]
Bases:
XAPhotosContainerList
A wrapper around lists of albums that employs fast enumeration techniques.
All properties of albums can be called as methods on the wrapped list, returning a list containing each album’s value for the property.
New in version 0.0.6.
Methods:
push
(container)Appends the object referenced by the provided PyXA wrapper to the end of the list.
- push(container: XAPhotosContainer)[source]
Appends the object referenced by the provided PyXA wrapper to the end of the list.
New in version 0.0.3.
- class PyXA.apps.PhotosApp.XAPhotosApplication(properties)[source]
Bases:
XASBApplication
,XACanOpenPath
A class for managing and interacting with Photos.app.
New in version 0.0.2.
Classes:
ObjectType
(value)Types of objects that can be created using
XAPhotosApplication.make()
.Methods:
add
(media_items, album)Adds the given list of media items to the specified album.
albums
([filter])Returns a list of albums, as PyXA objects, matching the given filter.
containers
([filter])Returns a list of containers, as PyXA objects, matching the given filter.
export
(media_items, destination_path[, ...])Exports a list of media items to the specified folder.
folders
([filter])Returns a list of folders, as PyXA objects, matching the given filter.
import_files
(files[, destination_album, ...])Imports a list of files into the specified album.
make
(specifier[, properties, data])Creates a new element of the given specifier class without adding it to any list.
media_items
([filter])Returns a list of media items, as PyXA objects, matching the given filter.
Skips to the next slide in the currently playing slideshow.
open
(path)Imports the file at the given filepath without adding it to any particular album.
Pauses the currently playing slideshow.
Skips to the previous slide in the currently playing slideshow.
Resumes the currently playing slideshow (from a paused state).
search
(query)Searches for items matching the given search string.
start_slideshow
(item_list)Starts an ad-hoc slideshow from the given list of media items, an album, or a folder.
Stops the currently playing slideshow.
Attributes:
Favorited media items album.
Whether Photos is the frontmost application.
The path to the Photos library container.
The name of the application.
All properties of the application.
The set of recently deleted media items.
The currently selected media items in the application.
Returns true if a slideshow is currently running.
The version of Photos.app.
- class ObjectType(value)[source]
Bases:
Enum
Types of objects that can be created using
XAPhotosApplication.make()
.Attributes:
- ALBUM = 'album'
- FOLDER = 'folder'
- add(media_items: XAPhotosMediaItemList | list[XAPhotosMediaItem], album: XAPhotosAlbum) XAPhotosApplication [source]
Adds the given list of media items to the specified album.
- Parameters:
media_items (Union[XAPhotosMediaItemList, list[XAPhotosMediaItem]]) – The media items to add
album (XAPhotosAlbum) – The album to add the media items to
- Returns:
The Photos application object
- Return type:
New in version 0.0.6.
- albums(filter: dict | None = None) XAPhotosAlbumList [source]
Returns a list of albums, as PyXA objects, matching the given filter.
- Parameters:
filter (Union[dict, None]) – A dictionary specifying property-value pairs that all returned albums will have, or None
- Returns:
The list of albums
- Return type:
New in version 0.0.6.
- containers(filter: dict | None = None) XAPhotosContainerList [source]
Returns a list of containers, as PyXA objects, matching the given filter.
- Parameters:
filter (Union[dict, None]) – A dictionary specifying property-value pairs that all returned containers will have, or None
- Returns:
The list of containers
- Return type:
New in version 0.0.6.
- export(media_items: XAPhotosMediaItemList | list[XAPhotosMediaItem], destination_path: str | NSURL, use_originals: bool = False) XAPhotosApplication [source]
Exports a list of media items to the specified folder.
- Parameters:
media_items (Union[XAPhotosMediaItemList, list[XAPhotosMediaItem]]) – The media items to export
destination_path (Union[str, NSURL]) – The folder to store the exported files in
use_originals (bool, optional) – Whether to export the original files or rendered jpgs, defaults to False
- Returns:
The Photos application object
- Return type:
New in version 0.0.6.
- property favorites_album: XAPhotosAlbum
Favorited media items album.
- folders(filter: dict | None = None) XAPhotosFolderList [source]
Returns a list of folders, as PyXA objects, matching the given filter.
- Parameters:
filter (Union[dict, None]) – A dictionary specifying property-value pairs that all returned folders will have, or None
- Returns:
The list of folders
- Return type:
New in version 0.0.6.
- property frontmost: bool
Whether Photos is the frontmost application.
- import_files(files: list[str | NSURL], destination_album: XAPhotosAlbum | None = None, skip_duplicate_checking: bool = False) XAPhotosMediaItemList [source]
Imports a list of files into the specified album.
- Parameters:
files (list[Union[str, NSURL]]) – The files to import
destination_album (Union[XAPhotosAlbum, None], optional) – The album to import items into, defaults to None
skip_duplicate_checking (bool, optional) – Whether the skip checking duplicates and import everything, defaults to False
- Returns:
The list of imported media items
- Return type:
New in version 0.0.6.
- make(specifier: str | ObjectType, properties: dict | None = None, data: Any | None = None)[source]
Creates a new element of the given specifier class without adding it to any list.
Use
XABase.XAList.push()
to push the element onto a list.- Parameters:
specifier (Union[str, XAPhotosApplication.ObjectType]) – The classname of the object to create
properties (dict) – The properties to give the object
data (Any, optional) – The data to initialize the object with, defaults to None
- Returns:
A PyXA wrapped form of the object
- Return type:
- Example 1:
Make a new album
>>> import PyXA >>> app = PyXA.Application("Photos") >>> new_album = app.make("album", {"name": "PyXA"}) >>> app.albums().push(new_album)
New in version 0.0.6.
- media_items(filter: dict | None = None) XAPhotosMediaItemList [source]
Returns a list of media items, as PyXA objects, matching the given filter.
- Parameters:
filter (Union[dict, None]) – A dictionary specifying property-value pairs that all returned media items will have, or None
- Returns:
The list of media items
- Return type:
New in version 0.0.6.
- property name: str
The name of the application.
- next_slide() XAPhotosApplication [source]
Skips to the next slide in the currently playing slideshow.
- Returns:
The Photos application object
- Return type:
New in version 0.0.6.
- open(path: str | XAPath | list[str | XAPath]) XAPhotosApplication [source]
Imports the file at the given filepath without adding it to any particular album.
- Parameters:
target (Union[str, XABase.XAPath, list[str, list[XABase.XAPath]]]) – The path to a file to import into photos.
- Returns:
The Photos application object
- Return type:
New in version 0.0.1.
- pause_slideshow() XAPhotosApplication [source]
Pauses the currently playing slideshow.
- Returns:
The Photos application object
- Return type:
New in version 0.0.6.
- previous_slide() XAPhotosApplication [source]
Skips to the previous slide in the currently playing slideshow.
- Returns:
The Photos application object
- Return type:
New in version 0.0.6.
- property properties: dict
All properties of the application.
- property recently_deleted_album: XAPhotosAlbum
The set of recently deleted media items.
- resume_slideshow() XAPhotosApplication [source]
Resumes the currently playing slideshow (from a paused state).
- Returns:
The Photos application object
- Return type:
New in version 0.0.6.
- search(query: str) XAPhotosMediaItemList [source]
Searches for items matching the given search string.
- Parameters:
query (str) – The string to search
- Returns:
A list of media items matching the search query
- Return type:
New in version 0.0.6.
- property selection: XAPhotosMediaItemList
The currently selected media items in the application.
- property slideshow_running: bool
Returns true if a slideshow is currently running.
- start_slideshow(item_list: XAPhotosMediaItemList | XAPhotosAlbum | XAPhotosFolder) XAPhotosApplication [source]
Starts an ad-hoc slideshow from the given list of media items, an album, or a folder.
- Parameters:
item_list (Union['XAPhotosMediaItemList', 'XAPhotosAlbum', 'XAPhotosFolder']) – The list of media items, an album, or a folder to create a slideshow from
- Returns:
The Photos application object
- Return type:
New in version 0.0.6.
- stop_slideshow() XAPhotosApplication [source]
Stops the currently playing slideshow.
- Returns:
The Photos application object
- Return type:
New in version 0.0.6.
- property version: str
The version of Photos.app.
- class PyXA.apps.PhotosApp.XAPhotosContainer(properties)[source]
Bases:
XAObject
,XAClipboardCodable
A class for…
Methods:
Gets a clipboard-codable representation of the container.
Shows the container in the front window of Photos.app.
Attributes:
The unique ID of this container.
The name of this container.
This container's parent folder, if any.
All properties of the container.
- get_clipboard_representation() str [source]
Gets a clipboard-codable representation of the container.
When the clipboard content is set to a container, the containers’s name is added to the clipboard.
- Returns:
The container’s name
- Return type:
str
New in version 0.0.8.
- property id: str
The unique ID of this container.
- property name: str
The name of this container.
- property parent: XAPhotosFolder
This container’s parent folder, if any.
- property properties: dict
All properties of the container.
- spotlight() XAPhotosContainer [source]
Shows the container in the front window of Photos.app.
- Returns:
The container object
- Return type:
New in version 0.0.6.
- class PyXA.apps.PhotosApp.XAPhotosContainerList(properties: dict, filter: dict | None = None, obj_class=None)[source]
Bases:
XAList
,XAClipboardCodable
A wrapper around lists of containers that employs fast enumeration techniques.
All properties of containers can be called as methods on the wrapped list, returning a list containing each container’s value for the property.
New in version 0.0.6.
Methods:
by_id
(id)by_name
(name)by_parent
(parent)by_properties
(properties)Gets a clipboard-codable representation of each container in the list.
id
()name
()parent
()- by_id(id: str) XAPhotosContainer | None [source]
- by_name(name: str) XAPhotosContainer | None [source]
- by_parent(parent: XAPhotosFolder) XAPhotosContainer | None [source]
- by_properties(properties: dict) XAPhotosContainer | None [source]
- get_clipboard_representation() str [source]
Gets a clipboard-codable representation of each container in the list.
When the clipboard content is set to a list of containers, each containers’s name is added to the clipboard.
- Returns:
The container’s name
- Return type:
str
New in version 0.0.8.
- parent() XAPhotosFolderList [source]
- class PyXA.apps.PhotosApp.XAPhotosFolder(properties)[source]
Bases:
XAPhotosContainer
A folder in Photos.app.
New in version 0.0.2.
Methods:
albums
([filter])Returns a list of albums, as PyXA objects, matching the given filter.
containers
([filter])Returns a list of containers, as PyXA objects, matching the given filter.
folders
([filter])Returns a list of folders, as PyXA objects, matching the given filter.
- albums(filter: dict | None = None) XAPhotosAlbumList [source]
Returns a list of albums, as PyXA objects, matching the given filter.
- Parameters:
filter (Union[dict, None]) – A dictionary specifying property-value pairs that all returned albums will have, or None
- Returns:
The list of albums
- Return type:
New in version 0.0.6.
- containers(filter: dict | None = None) XAPhotosContainerList [source]
Returns a list of containers, as PyXA objects, matching the given filter.
- Parameters:
filter (Union[dict, None]) – A dictionary specifying property-value pairs that all returned containers will have, or None
- Returns:
The list of containers
- Return type:
New in version 0.0.6.
- folders(filter: dict | None = None) XAPhotosFolderList [source]
Returns a list of folders, as PyXA objects, matching the given filter.
- Parameters:
filter (Union[dict, None]) – A dictionary specifying property-value pairs that all returned folders will have, or None
- Returns:
The list of folders
- Return type:
New in version 0.0.6.
- class PyXA.apps.PhotosApp.XAPhotosFolderList(properties: dict, filter: dict | None = None)[source]
Bases:
XAPhotosContainerList
A wrapper around lists of folders that employs fast enumeration techniques.
All properties of folders can be called as methods on the wrapped list, returning a list containing each folder’s value for the property.
New in version 0.0.6.
Methods:
push
(container)Appends the object referenced by the provided PyXA wrapper to the end of the list.
- push(container: XAPhotosContainer)[source]
Appends the object referenced by the provided PyXA wrapper to the end of the list.
New in version 0.0.3.
- class PyXA.apps.PhotosApp.XAPhotosMediaItem(properties)[source]
Bases:
XAObject
,XAClipboardCodable
,XAImageLike
A photo or video in Photos.app.
New in version 0.0.2.
Attributes:
The GPS altitude in meters.
The creation date of the media item.
The duration of the media item.
Whether the media item has been favorited.
The path to the main file for the media item.
The name of the file on disk.
The height of the media item in pixels.
The unique ID of the media item.
Whether the media item is a burst photo.
Whether the media item is hidden.
Whether the media item is a photo.
Whether the media item is a video.
A list of keywords to associate with a media item.
The GPS latitude and longitude, in an ordered list of 2 numbers or missing values.
The last modification date of the media item.
The name (title) of the media item.
A description of the media item.
All properties of the media item.
The selected media item file size.
The width of the media item in pixels.
Methods:
Duplicates the media item.
Gets a clipboard-codable representation of the media item.
Gets a representation of the object that can be used to initialize an
XAImage
object.Opens a Finder window or tab focused on the media item's containing folder with the media item selected.
Opens the media item in Preview.app.
Shows the media item in the front window of Photos.app.
- property altitude: float
The GPS altitude in meters.
- property creation_date: datetime
The creation date of the media item.
- duplicate() XAPhotosMediaItem [source]
Duplicates the media item.
- Returns:
The newly created media item object
- Return type:
New in version 0.0.2.
- property duration: float
The duration of the media item.
- property favorite: bool
Whether the media item has been favorited.
- property filename: str
The name of the file on disk.
- get_clipboard_representation() NSURL [source]
Gets a clipboard-codable representation of the media item.
When the clipboard content is set to a media item, the item’s file URL is added to the clipboard.
- Returns:
The media item’s file URL
- Return type:
NSURL
New in version 0.0.8.
- get_image_representation() XAPath [source]
Gets a representation of the object that can be used to initialize an
XAImage
object.- Returns:
The XAImage-compatible form of this object
- Return type:
- property height: int
The height of the media item in pixels.
- property id: str
The unique ID of the media item.
- property is_burst: bool
Whether the media item is a burst photo.
Whether the media item is hidden.
- property is_photo: bool
Whether the media item is a photo.
- property is_video: bool
Whether the media item is a video.
- property keywords: list[str]
A list of keywords to associate with a media item.
- property location: XALocation
The GPS latitude and longitude, in an ordered list of 2 numbers or missing values. Latitude in range -90.0 to 90.0, longitude in range -180.0 to 180.0.
- property modification_date: datetime
The last modification date of the media item.
- property name: str
The name (title) of the media item.
- property object_description: str
A description of the media item.
- property properties: dict
All properties of the media item.
- reveal_in_finder()[source]
Opens a Finder window or tab focused on the media item’s containing folder with the media item selected.
New in version 0.0.2.
- property size: int
The selected media item file size.
- spotlight() XAPhotosMediaItem [source]
Shows the media item in the front window of Photos.app.
- Returns:
The media item object
- Return type:
New in version 0.0.6.
- property width: int
The width of the media item in pixels.
- class PyXA.apps.PhotosApp.XAPhotosMediaItemList(properties: dict, filter: dict | None = None)[source]
Bases:
XAList
,XAClipboardCodable
A wrapper around lists of media items that employs fast enumeration techniques.
All properties of media items can be called as methods on the wrapped list, returning a list containing each media item’s value for the property.
New in version 0.0.6.
Methods:
altitude
()by_altitude
(altitude)by_date
(date)by_favorite
(favorite)by_filename
(filename)by_height
(height)by_id
(id)by_keywords
(keywords)by_location
(location)by_object_description
(object_description)by_properties
(properties)by_size
(size)by_title
(title)by_width
(width)duration
()favorite
()filename
()Gets a clipboard-codable representation of each media item in the list.
height
()id
()is_burst
()is_photo
()is_video
()keywords
()location
()size
()title
()width
()- by_altitude(altitude: float) XAPhotosMediaItem | None [source]
- by_date(date: datetime) XAPhotosMediaItem | None [source]
- by_favorite(favorite: bool) XAPhotosMediaItem | None [source]
- by_filename(filename: str) XAPhotosMediaItem | None [source]
- by_height(height: int) XAPhotosMediaItem | None [source]
- by_id(id: str) XAPhotosMediaItem | None [source]
- by_keywords(keywords: list[str]) XAPhotosMediaItem | None [source]
- by_location(location: XALocation) XAPhotosMediaItem | None [source]
- by_object_description(object_description: str) XAPhotosMediaItem | None [source]
- by_properties(properties: dict) XAPhotosMediaItem | None [source]
- by_size(size: int) XAPhotosMediaItem | None [source]
- by_title(title: str) XAPhotosMediaItem | None [source]
- by_width(width: int) XAPhotosMediaItem | None [source]
- get_clipboard_representation() list[NSURL] [source]
Gets a clipboard-codable representation of each media item in the list.
When the clipboard content is set to a list of media items, each item’s file URL is added to the clipboard.
- Returns:
A list of media item file URLs
- Return type:
list[NSURL]
New in version 0.0.8.