Skip to content

Commit

Permalink
add support for multiple images in a file list
Browse files Browse the repository at this point in the history
  • Loading branch information
luckman212 committed Feb 28, 2023
1 parent 872dffc commit afccd3f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 45 deletions.
87 changes: 43 additions & 44 deletions cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ https://www.alfredforum.com/topic/14400-clipsaver-save-images-from-clipboard-his
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>2.2.1</string>
<string>2.3.0</string>
<key>webaddress</key>
<string>https://github.com/luckman212/alfred_clipsaver_workflow</string>
</dict>
Expand Down

0 comments on commit afccd3f

Please sign in to comment.