Jump to content

Edit clipboard before pasting


Recommended Posts

@manavortex @Ovi What kind of modification do you have in mind when wanting to change text in the item you've copied to clipboard?


To be clear, we have no intention of adding a text editor to Alfred to edit arbitrary text before pasting, but there may be some clever ways you can do what you want with a workflow or snippet.


For example, if you have text that you want to paste with a few repeated changes every time (e.g. change someone's name, the price of something, etc), that could be achieved using a dynamic placeholder in a snippet. It's a much more efficient way and predictable way to paste something with specific elements changed every time.


If that's what you have in mind, take a look at the built-in workflow Getting Started > Snippet Triggers to see them in action. You'll also find a tutorial on using Snippet Triggers with dynamic content here:



If you have something else in mind, do share, as there may very well be ways to do it already :)





Link to comment
Share on other sites



my main use case is copying URLs from Safari and removing the referrers via regex. Currently I'm doing it via keyboard maestro, my regex (for now) is 



If I have an URL like 


that basically leaves



Since Alfred already has a builtin clipboard manager, it would be my tool of choice. 


What I'd like would be one of the following: 

  • Trigger an Alfred workflow on external clipboard change (to avoid endless recursion)
    • Advantage: Greater flexibility
    • Disadvantage: Another kind of trigger that you might not want to replace
  • A feature to the Alfred clipboard manager to replace clipboard content based on rules
    • Advantage: More foolproof
    • Disadvantage: Would probably require major changes..? 

Please let me know how I can achieve that with built-in means! 

Edited by manavortex
wrong syntax highlighting
Link to comment
Share on other sites

  • 2 years later...

I ran into a case where I wanted to copy & paste a little recipe of commands with small changes that varied each time I used the recipe. Rather than making an Alfred workflow for the specific task, I thought it would be more useful to simply copy my recipe and then edit it before pasting. Surely Alfred would help me with that! 😀 A google search for "alfredapp edit clipboard" led me to this thread, but not to the solution I was seeking. So I thought I would share my solution...


My solution for this was to use an editor (in my case Sublime Text) that supports editing of stdin. Sublime Text offers a command line option for editing stdin in the form:


subl -


That will open the editor with the contents of stdin and return whatever is saved from that editor to stdout. All I needed to do was pipe the clipboard into this and then send the output back to the clipboard. That's a piece of cake for Alfred. So, I chose a hotkey (⌥⇧V) to be my "edit before paste" hotkey and linked it to a bash script with this single line:


pbpaste | /Users/username/bin/subl -


where "username" is my MacOS username. This needs to be have the full path to the subl command (which you can find from the terminal using "which subl". I could get something like "$(which subl) -" or "$(command -v subl) - " to work to avoid having to hardcode the full path.


Finally, the output from the editor is passed to a Copy to Clipboard output (with "Automatically paste to front most app" selected).


With this workflow, if I want to edit the clipboard before pasting, I press ⌥⇧V, my editor comes up with the clipboard contents, I make my edits & save, and the edited value gets pasted into whatever app I was in when I pressed the hotkey. Voilà!



Link to comment
Share on other sites

  • 2 years later...
On 11/7/2018 at 5:47 PM, Vero said:

What kind of modification do you have in mind when wanting to change text in the item you've copied to clipboard?

So, I have this brain dead bank with their ultra fancy Javacript that .. well... it break things like entering cellphone numbers, where it contains spaces where you copied it from, and the input box then totally stop right there in it's tracks and you can't paste the rest.

ie. the data I'm pasting: 

78 123 674

the effect in the input box:


as the space then stops any further input /parsing ;(
to be able to remove the spaces in THIS case, would be fantastic (actually to also remove tabs will be a blessing in other cases)

Link to comment
Share on other sites

Does the data have to come from the clipboard? Is it standard on each occasion or is it some changeable code?


If standard you might consider a workflow that incorporates the Replace utility—so long as you don't mind working with Regular Expressions.





Link to comment
Share on other sites

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