From afccd3f81b3a7f60da8297904dc958e90be667dd Mon Sep 17 00:00:00 2001
From: luckman212 <1992842+luckman212@users.noreply.github.com>
Date: Tue, 28 Feb 2023 00:33:34 -0500
Subject: [PATCH] add support for multiple images in a file list
---
cs.py | 87 +++++++++++++++++++++++++++---------------------------
info.plist | 2 +-
2 files changed, 44 insertions(+), 45 deletions(-)
diff --git a/cs.py b/cs.py
index 19a191d..8f028d5 100644
--- a/cs.py
+++ b/cs.py
@@ -51,6 +51,39 @@ def database(path):
yield db
db.close()
+def append_item(fn, img, title, sub, srcapp, ctime):
+ global uidSeed, fmt, items
+ if not os.path.exists(img):
+ return
+ il = img.lower()
+ if not any(i['arg'] == il for i in items):
+ items.append({
+ "uid": ''.join([ uidSeed, '.', fn ]),
+ "variables": { "uidSeed": uidSeed },
+ "title": title,
+ "subtitle": ctime + f' ↩ save as {fmt.upper()}',
+ "arg": il,
+ "type": "file:skipcheck",
+ "variables": {
+ "format": fmt.lower()
+ },
+ "icon": { "path": img },
+ "mods": {
+ "alt": {
+ "arg": il,
+ "subtitle": ' '.join([ 'from:', sub ])
+ },
+ "cmd": {
+ "arg": img,
+ "subtitle": ' '.join([ str(img), '(reveal)' ]),
+ "variables": {
+ "action": 'reveal'
+ }
+ }
+ },
+ "quicklookurl": img
+ })
+
def listitems(fmt='png',num=1):
if num > 1:
items.append({
@@ -66,56 +99,22 @@ def listitems(fmt='png',num=1):
#0=filename, 1=title, 2=src app, 3=time, 4=type (1=image from db,2=files)
rows = db.execute("SELECT dataHash,item,apppath,strftime('%Y-%m-%d %H:%M',ts+978307200,'unixepoch','localtime'),dataType from clipboard WHERE dataType IN (1,2) ORDER BY rowid DESC LIMIT ?", [sf_clip_limit])
for r in rows:
- srcpath = os.path.join(i_path, r[0])
- if r[4] == 2:
+ (fn, title, srcapp, ctime, dtype) = r
+ img = srcpath = os.path.join(i_path, fn)
+ if dtype == 2:
try:
with open(srcpath, "rb") as fp:
plistobj = plistlib.load(fp)
- img = next(i for i in plistobj if i.split(os.extsep)[-1].lower() in img_exts)
- assert os.path.exists(img)
except:
continue
- title = ' '.join([ "File:", img ])
- icon = { "path": img }
- sub = "File List"
- elif r[2] is None:
- title = r[1]
- icon = { "path": img }
- sub = "(unknown)"
- #match = 'unknown'
+ imgfiles = [i for i in plistobj if i.split(os.extsep)[-1].lower() in img_exts]
+ for img in imgfiles:
+ title = ' '.join([ "File:", img ])
+ sub = f"File List {fn}"
+ append_item(fn,img,title,sub,srcapp,ctime)
else:
- img = srcpath
- title = r[1]
- icon = { "path": img }
- sub = r[2]
- #match = sub.replace('/', ' / ')
- items.append({
- "uid": ''.join([ uidSeed, '.', r[0] ]),
- "variables": { "uidSeed": uidSeed },
- "title": title,
- "subtitle": r[3] + f' ↩ save as {fmt.upper()}',
- "arg": img.lower(),
- "type": "file:skipcheck",
- "variables": {
- "format": fmt.lower()
- },
- #"match": match,
- "icon": icon,
- "mods": {
- "alt": {
- "arg": img.lower(),
- "subtitle": ' '.join([ 'from:', sub ])
- },
- "cmd": {
- "arg": img,
- "subtitle": ' '.join([ str(img), '(reveal)' ]),
- "variables": {
- "action": 'reveal'
- }
- }
- },
- "quicklookurl": img
- })
+ sub = srcapp or "(unknown)"
+ append_item(fn,img,title,sub,srcapp,ctime)
try:
args = sys.argv[1].split()
diff --git a/info.plist b/info.plist
index 39996d8..d03e182 100644
--- a/info.plist
+++ b/info.plist
@@ -801,7 +801,7 @@ https://www.alfredforum.com/topic/14400-clipsaver-save-images-from-clipboard-his
variablesdontexport
version
- 2.2.1
+ 2.3.0
webaddress
https://github.com/luckman212/alfred_clipsaver_workflow