Jump to content

ClipSaver - save images from clipboard history to PNG files


Recommended Posts

Hey guys,

Thought I'd share this little workflow. I found myself often needing to dump out the last N clipboard images from Alfred's history to disk. It was tedious before, find the right item, copy it back to the pasteboard, paste into Preview, save as PNG, give it a non-overlapping name, etc. So I created this to make it semi-automatic. Shouldn't need anything special, but please let me know if you run into any trouble.

 

Feedback welcome! One thing for sure I would like some advice on is whether the Script Filter (Python) could be turned back into a List Comprehension which from what I've read is more efficient. I couldn't figure out how to do that and also dynamically update the database rows (e.g. converting "/" to " / " so that Alfred's word matching would match correctly, picking a nicer generic icon when app name==null etc). @deanishe if you have time I'm sure you know the answer to this... :) 

 

image.png.9496718f9e287a6b37b27c8632462765.png

 

README & download:

https://github.com/luckman212/alfredworkflows/blob/master/clipsaver_readme.md

 

 

Edited by luckman212
Link to post

Just to clarify what I was asking about above with the List Comprehensions, I'm talking about this.

 

Populating the list using List Comprehension

items = []
with database(dbpath) as db:
    rows = db.execute("SELECT foo...)
    items = [{ "title": r[1],
               "arg": r[0]
             } for r in rows ]

Populating the list using a loop and append (this is the current method used)

items = []
with database(db_path) as db:
    rows = db.execute("SELECT bar...)
    for r in rows:
      if r[2] == None:
        (...do stuff...)
      else:
        (...do other stuff...)
      items.append({ "title": r[1],
                     "arg": r[0]
                   })

My question is, is there a way to use the List Comprehension method while still allowing for the if/then/else code to execute?

Link to post
2 hours ago, luckman212 said:

My question is, is there a way to use the List Comprehension method while still allowing for the if/then/else code to execute?

 

Not in this case, no. But forget about it. The difference in performance is absolutely miniscule and list comprehensions should be used sparingly. Readable code is more important that the tiny bit of speed you get from replacing a loop with a list comprehension.

 

2 hours ago, luckman212 said:

if r[2] == None:

 

if r[2] is None: is the more idiomatic way to test for None.

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...