luckman212 Posted February 7, 2020 Share Posted February 7, 2020 (edited) Latest release: v2.3.5 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 March 15 by luckman212 evanfuchs, giovanni, kpw and 2 others 5 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
evanfuchs Posted February 9 Share Posted February 9 Any idea why the list of images returned by this workflow would be different than Alfred's Clipboard History feature? When I take a screenshot to the clipboard, it appears in Alfred's results but not in this workflows results. Not sure what other info to provide to help me troubleshoot. Link to comment
luckman212 Posted February 12 Author Share Posted February 12 @evanfuchs Does the workflow return any results? My initial thought is: you may have configured the database path incorrectly. If you open Alfred's debugger (⌘D from the Workflow screen) and trigger the workflow, what's the output there? Any errors? (maybe you can paste the results to a pastebin...) Link to comment
evanfuchs Posted February 15 Share Posted February 15 (edited) @luckman212 Thanks for the reply. Yes, it does show results, but only partial results compared to Alfred's Clipboard History feature. No errors in the debug window, but I looked at the database folder as configured in the workflow, and I found a subfolder "clipboard.alfdb.data" with two types of files: tiff and plist, where each plist is a reference to a file in my screen shots folder. This workflow seems to be showing the tiffs, but not the items referenced in the plists. Alfred's Clipboard History shows both. I hope that explanation makes sense and is helpful! Edited February 15 by evanfuchs Link to comment
luckman212 Posted February 23 Author Share Posted February 23 @evanfuchs I may be misunderstanding, sorry if that's the case, but—the purpose of this workflow is to only show/save IMAGES. So it is expected that the workflow's results will be limited to the TIFFs only, and will be different from Alfred's clipboard history which would contain all items: files, text etc. Are you expecting something different? Link to comment
evanfuchs Posted February 23 Share Posted February 23 I am talking about images only. It seems some items in Alfred’s history are not stored directly in that location, but rather as references (plists) to images in another location. Alfred shows all the images (those actually in the folder and those referenced) but this workflow doesn’t seem to see the referenced images. I don’t know enough about Alfred works under the hood to explain further. Just an observation. Link to comment
luckman212 Posted February 23 Author Share Posted February 23 The workflow reads directly from Alfred's SQLite database, so it's very unexpected that the results would be different from what you see in Alfred's native UI. I am not in front of my computer now, but I'll update this post later with some diagnostic commands to run, hopefully that may shed some light on what's going on here. Link to comment
evanfuchs Posted February 23 Share Posted February 23 Okay sounds good. Thanks for sticking with me. I will check back later. Link to comment
luckman212 Posted February 24 Author Share Posted February 24 (edited) @evanfuchs Ok let's start with some basics: Open a Terminal and try entering in the following commands. Please copy & paste the results to a pastebin. cd "$HOME/Library/Application Support/Alfred/Databases" ls -l clipboard.alfdb.data sqlite3 -header clipboard.alfdb 'SELECT * FROM clipboard WHERE dataType == 1' Finally, open Alfred and select the Workflows tab, then open the Debugger console (⌘D) and trigger ClipSaver. Copy and paste the JSON output to a separate pastebin. Edited February 24 by luckman212 Link to comment
oorbx Posted February 25 Share Posted February 25 On 11/18/2022 at 8:31 AM, cartern said: I got error below even there is a pic in the clip. very strange, i have same error anyhow i see in alfred snippet clipboard image as the latest one, this error message will occurs. Link to comment
luckman212 Posted February 25 Author Share Posted February 25 @oorbx What does your Debug console output look like in Alfred? Please post it- same steps that I was looking to see from Evan Fuchs above Link to comment
oorbx Posted February 26 Share Posted February 26 (edited) On 2/26/2023 at 12:26 AM, luckman212 said: @oorbx What does your Debug console output look like in Alfred? Please post it- same steps that I was looking to see from Evan Fuchs above Hey there, sorry i dont know how to work and share pastebin. I paste there, but i dont know whats next. Thats why i paste to here: Last login: Sun Feb 26 09:11:38 on ttys000 xxx@MacBook-xPro ~ % cd "$HOME/Library/Application Support/Alfred/Databases" xxx@MacBook-xPro Databases % ls -l clipboard.alfdb.data total 24 -rw-r--r--@ 1 xxx staff 335 26 feb 09:11 23cb2faaa08dc4b7aa34cbac2d28d4ba425b0709.plist -rw-r--r--@ 1 xxx staff 245 25 feb 21:47 2890925619460226d9da225abed2e2bae052c769.plist -rw-r--r--@ 1 xxx staff 244 25 feb 22:07 348bfa64dacc725130316704bc58ace684e4c291.plist xxx@MacBook-xPro Databases % sqlite3 -header clipboard.alfdb 'SELECT * FROM clipboard WHERE dataType == 1' xxx@MacBook-xPro Databases % [09:15:51.908] Logging Started... [09:16:18.154] ClipSaver[Script Filter] Queuing argument '(null)' [09:16:18.190] ClipSaver[Script Filter] Script with argv '(null)' finished [09:16:18.196] ClipSaver[Script Filter] {"variables": {"uidSeed": "1677399378.185623"}, "skipknowledge": true, "items": [{"title": "No image clips found", "subtitle": "clipboard history may be empty", "icon": {"path": "error.png"}, "valid": false}]} Edited March 1 by oorbx 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