Jump to content

Restoring clipboard contents after "Copy to Clipboard" action


Recommended Posts

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 ⤵

 

2009400350_ScreenShot2019-10-09at2_50_43PM.png.fc8bd42b003c0b6eaa40484690b692b8.png

 

Any help would be appreciated!

 

 

 

 

 

(And another image of my "Copy to Clipboard" settings in this workflow attached)

Screen Shot 2019-10-09 at 2.51.45 PM.png

Edited by mackenzie
Moved config attachment around in post
Link to comment
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 by deanishe
Link to comment

@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 💙

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...