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 ⤵




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 post
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 post

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

Join the conversation

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

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...