From 2e1c91cd672eefe84063933437e5d691f5ad1db1 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Fri, 2 Jul 2021 13:19:15 -0700 Subject: [PATCH] Added get_selected() to REPL --- osxphotos/_version.py | 2 +- osxphotos/cli.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/osxphotos/_version.py b/osxphotos/_version.py index c1de42bd..e4ce5819 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.42.53" +__version__ = "0.42.54" diff --git a/osxphotos/cli.py b/osxphotos/cli.py index 76db124d..342f4498 100644 --- a/osxphotos/cli.py +++ b/osxphotos/cli.py @@ -16,6 +16,7 @@ import time import bitmath import click import osxmetadata +import photoscript import yaml from rich import pretty @@ -3900,11 +3901,24 @@ def _load_photos_db(dbpath): def _get_photos(photosdb): + """get list of all photos in photosdb""" photos = photosdb.photos(images=True, movies=True) photos.extend(photosdb.photos(images=True, movies=True, intrash=True)) return photos +def _get_selected(photosdb): + """get list of PhotoInfo objects for photos selected in Photos""" + + def get_selected(): + selected = photoscript.PhotosLibrary().selection + if not selected: + return [] + return photosdb.photos(uuid=[p.uuid for p in selected]) + + return get_selected + + @cli.command() @DB_OPTION @click.pass_obj @@ -3925,6 +3939,7 @@ def repl(ctx, cli_obj, db): # shortcut for helper functions get_photo = photosdb.get_photo show = _show_photo + get_selected = _get_selected(photosdb) print(f"Found {len(photos)} photos in {tictoc:0.2f} seconds") print("The following variables are defined:") @@ -3934,6 +3949,7 @@ def repl(ctx, cli_obj, db): ) print(f"\nThe following functions may be helpful:") print(f"- get_photo(uuid): return a PhotoInfo object for photo with uuid") + print(f"- get_selected(): return list of PhotoInfo objects for photos selected in Photos") print(f"- show(photo): open a photo object in the default viewer") print( f"- help(object): print help text including list of methods for object; for example, help(PhotosDB)"