Added --selected, closes #489
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
""" version info """
|
||||
|
||||
__version__ = "0.42.60"
|
||||
__version__ = "0.42.61"
|
||||
|
||||
@@ -536,6 +536,11 @@ def QUERY_OPTIONS(f):
|
||||
"For example, to find photos in an album that begins with 'Beach': '--regex \"^Beach\" \"{album}\"'. "
|
||||
"You may specify more than one regular expression match by repeating '--regex' with different arguments.",
|
||||
),
|
||||
o(
|
||||
"--selected",
|
||||
is_flag=True,
|
||||
help="Filter for photos that are currently selected in Photos.",
|
||||
),
|
||||
o(
|
||||
"--query-eval",
|
||||
metavar="CRITERIA",
|
||||
@@ -1182,6 +1187,7 @@ def export(
|
||||
min_size,
|
||||
max_size,
|
||||
regex,
|
||||
selected,
|
||||
query_eval,
|
||||
query_function,
|
||||
duplicate,
|
||||
@@ -1345,6 +1351,7 @@ def export(
|
||||
min_size = cfg.min_size
|
||||
max_size = cfg.max_size
|
||||
regex = cfg.regex
|
||||
selected = cfg.selected
|
||||
query_eval = cfg.query_eval
|
||||
query_function = cfg.query_function
|
||||
duplicate = cfg.duplicate
|
||||
@@ -1663,6 +1670,7 @@ def export(
|
||||
min_size=min_size,
|
||||
max_size=max_size,
|
||||
regex=regex,
|
||||
selected=selected,
|
||||
query_eval=query_eval,
|
||||
function=query_function,
|
||||
duplicate=duplicate,
|
||||
@@ -2071,6 +2079,7 @@ def query(
|
||||
min_size,
|
||||
max_size,
|
||||
regex,
|
||||
selected,
|
||||
query_eval,
|
||||
query_function,
|
||||
add_to_album,
|
||||
@@ -2105,6 +2114,7 @@ def query(
|
||||
min_size,
|
||||
max_size,
|
||||
regex,
|
||||
selected,
|
||||
duplicate,
|
||||
]
|
||||
exclusive = [
|
||||
@@ -2235,6 +2245,7 @@ def query(
|
||||
query_eval=query_eval,
|
||||
function=query_function,
|
||||
regex=regex,
|
||||
selected=selected,
|
||||
duplicate=duplicate,
|
||||
)
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ from pprint import pformat
|
||||
from typing import List
|
||||
|
||||
import bitmath
|
||||
import photoscript
|
||||
|
||||
from .._constants import (
|
||||
_DB_TABLE_NAMES,
|
||||
@@ -3324,6 +3325,18 @@ class PhotosDB:
|
||||
elif options.no_location:
|
||||
photos = [p for p in photos if p.location == (None, None)]
|
||||
|
||||
if options.selected:
|
||||
# photos selected in Photos app
|
||||
try:
|
||||
# catch AppleScript errors as the scripting interfce to Photos is flaky
|
||||
selected = photoscript.PhotosLibrary().selection
|
||||
selected_uuid = [p.uuid for p in selected]
|
||||
photos = [p for p in photos if p.uuid in selected_uuid]
|
||||
except Exception:
|
||||
# no photos selected or a selected photo was "open"
|
||||
# selection only works if photos selected in main media browser
|
||||
photos = []
|
||||
|
||||
if options.function:
|
||||
for function in options.function:
|
||||
photos = function[0](photos)
|
||||
|
||||
@@ -83,6 +83,7 @@ class QueryOptions:
|
||||
location: Optional[bool] = None
|
||||
no_location: Optional[bool] = None
|
||||
function: Optional[List[Tuple[callable, str]]] = None
|
||||
selected: Optional[bool] = None
|
||||
|
||||
def asdict(self):
|
||||
return asdict(self)
|
||||
|
||||
Reference in New Issue
Block a user