mackenzie Posted October 9, 2019 Posted October 9, 2019 (edited) Is there an action or hacky way to restore the previous contents of your clipboard after running a workflow that pastes a string (determined by `{query}`) into your front-most app? Example use case: I use unicode-symbols-search ↗ to paste unicode symbols into my frontmost app using `uni {query}`. I probably most often use this to insert the symbol "↗" (lol) after link text to indicate that the text is a link, and then paste the destination link afterwards, but if I use this workflow (or any workflow with the "Copy to Clipboard" action), the pasted string overrides the link I had in my clipboard. Checking "Mark item as transient in clipboard" to true doesn't seem to have the behaviour I'm looking for. Is there a way (or action) to restoring previous clipboard contents after "Copy to Clipboard" action? Quick example of what how I imagine this working here ⤵ Any help would be appreciated! (And another image of my "Copy to Clipboard" settings in this workflow attached) Edited October 9, 2019 by mackenzie Moved config attachment around in post
deanishe Posted October 9, 2019 Posted October 9, 2019 (edited) 1 hour ago, mackenzie said: Is there an action or hacky way to restore the previous contents of your clipboard after running a workflow that pastes a string The simple answer is "use a snippet if possible" because Alfred will do that for you. More generally, you need to save the current contents of the clipboard (using, e.g., pbpaste), run your Paste action, wait for a fraction of a second for the paste to complete, and then restore the clipboard (pbcopy). The problem is that pbcopy and pbpaste only understand text. If you want it to work with all types of data, you'll have to mess around with AppKit and NSPasteboard. Edited October 9, 2019 by deanishe mackenzie 1
vitor Posted October 10, 2019 Posted October 10, 2019 Connect two Copy to Clipboard Output, but add a Delay Utility between them (even 0.5 seconds worked, in my tests). On the second Copy to Clipboard Output, have {clipboard:1} instead of {query}. deanishe, evanfuchs and mackenzie 3
deanishe Posted October 10, 2019 Posted October 10, 2019 That's a lot simpler and smarter than what I said.
mackenzie Posted October 10, 2019 Author Posted October 10, 2019 @deanishe Thanks for suggestion yday - got working this morning by using your advice w `pbcopy` and `pbpaste` w the Python file for that Uni workflow, making the original clipboard contents a var, running the script, then afterwards restoring the var to the clipboard, but was ultra messy lol and not easily reproducible for other workflows. I appreciate the help - good place to start : ~ ) @vitor Huge - thanks - This works! 🥰 v clean Appreciate the help 💙
mackenzie Posted October 10, 2019 Author Posted October 10, 2019 @deanishe damn just took in that you wrote the py lib - bless
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