luckman212 Posted February 7, 2020 Share Posted February 7, 2020 (edited) Update: v2.0.4 is out with some enhancements. 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... GitHub https://github.com/luckman212/alfred_clipsaver_workflow Download Latest Release: https://github.com/luckman212/alfred_clipsaver_workflow/releases/latest/ Edited April 2, 2022 by luckman212 evanfuchs, giovanni and Krs 3 Link to comment
luckman212 Posted February 7, 2020 Author Share Posted February 7, 2020 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 comment
deanishe Posted February 7, 2020 Share Posted February 7, 2020 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 comment
luckman212 Posted February 7, 2020 Author Share Posted February 7, 2020 Much appreciated. I have a few other things planned for this workflow, I'll definitely make that adjustment. Link to comment
luckman212 Posted February 10, 2020 Author Share Posted February 10, 2020 I uploaded v1.0.3 that has that change and 1 other small fix for bulk mode. Link to comment
luckman212 Posted February 14, 2020 Author Share Posted February 14, 2020 v 1.1.0 uploaded, changes the bulk mode from a keyword trigger to a script filter so it can do some additional error checking and grab max_clips by counting the # if images in the history. JJJJ 1 Link to comment
noisyneil Posted February 15, 2022 Share Posted February 15, 2022 This is brilliant! Would you be able to tell me how to get the files to save straight to the desktop, rather than create a folder each time? I looked at the code block to try and change the directory but couldn't find "saved_clips". Link to comment
luckman212 Posted February 15, 2022 Author Share Posted February 15, 2022 @noisyneil sure, all you would need to do is edit the "dest_dir" workflow variable and set it to just "Desktop": noisyneil 1 Link to comment
noisyneil Posted February 15, 2022 Share Posted February 15, 2022 Wow! I didn't even know Alfred had a variables viewer!! Thanks! That works perfectly! 👏🏼👏🏼👏🏼 Link to comment
luckman212 Posted February 15, 2022 Author Share Posted February 15, 2022 Great. Yes I suggest you learn a little more about the Workflows, they are very powerful. Each workflow has its own variables. Start here: https://www.alfredapp.com/help/workflows/advanced/variables/ noisyneil 1 Link to comment
noisyneil Posted February 15, 2022 Share Posted February 15, 2022 I'm a big Keyboard Maestro fan, so I totally understand the usefulness of variables; just never built anything complex enough to require them in Alfred. Thanks for the link - I'll get learning! Link to comment
luckman212 Posted April 2, 2022 Author Share Posted April 2, 2022 Moved this to its own repo and updated slightly to v2.0.4 see original post... Link to comment
cartern Posted November 18, 2022 Share Posted November 18, 2022 I got error below even there is a pic in the clip. Link to comment
luckman212 Posted November 18, 2022 Author Share Posted November 18, 2022 Ok, let me see if I can help. 1. Can you post a screenshot or copy/paste the output of your Alfred debugger console? 2. Please post a screenshot of the workflow's Environment Variables area. 3. What version of Alfred and macOS are you running? 4. And finally, can you open a Terminal and type "python3 -VV" and paste that output here as well? Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now