Jump to content

Filter clipboard through your favourite one-liners

Recommended Posts

A deceptively simple workflow to process the contents of the clipboard through your one-liner of choice.


Behind the scenes this is just running pbpaste | {query} | pbcopy, so its power is limited only by your skill at the command line and imagination  :ph34r:


Download / Source


Note: Alfred 2 currently strips hotkey settings for safety, so if you want to initiate the prompt by hotkey for extra ninja-fu, you'll need to set your own. I personally favour Cmd+Shift+|



Edited by isometry
Link to comment

Not sure people are feeling the love for this one :huh: so I've added some built-in one-liners to try and illustrate its power. I've used it at least 5 times today already.


Examples include:

  • filtering the contents of the clipboard with grep
  • modifying the contents of the clipboard with sed, awk or perl
  • base64 encoding/decoding the clipboard
  • encrypting/decrypting the clipboard with AES-256
  • sorting the clipboard
  • reversing the lines in the clipboard
  • strip blank lines from the clipboard
  • upper/lowercasing the clipboard
  • add line numbers to the clipboard

full listing of the built-ins

Link to comment

Added a Hotkey object to the start of the workflow: once defined, you can save a few keystrokes. Copy the text you want to process, hit your hotkey, enter your one-liner and paste the results.


Very, very nice workflow.


If you change the hotkey to 'Selection in OS/X', it will auto-copy the selected text to the clipboard for you. Then you can connect the hotkey to a one-line bash script that does this:


osascript -e 'tell application "Alfred 2" to search "| "'


Then the hotkey copies the selected text and triggers the workflow in one step.


You can also take the 'pbcopy' out of the zsh script and put the 'Copy to Clipboard' step at the end. Then you can check the box 'Automatically paste to front most app'. Now, when you select text, trigger the hotkey and select a filter, the result will replace the selected text.


In addition, the list of items is clearer (at least to me) when the description is the title and the command-line is the subtitle. So, with a few formatting changes, it looks like this:


title: Encode base64 (builtin)

subtitle: openssl base64 -e

Edited by ctwise
Link to comment

@ctwise: excellent tips regards Selection in OS X and Automatically paste to front most app - thank you! I'll think about how best to integrate them into the release in such a way that (ideally) both behaviours are available. What you suggest is actually what I originally had in mind, though it doesn't necessarily fit well with, for example, selecting text from a terminal window.


Regards the format of feedback, I did try it that way around, but because you can (and should!) define your own aliases, which (currently) lack descriptions, it didn't make sense to do so. I could change the syntax, of course: | define description==pipeline@@. What do you think?

Link to comment
  • 3 months later...
  • 2 months later...

Hey ismoetry,


I installed your workflow and find it very useful. Thank you.


I do not know shell scripting enough to solve the problem I have, copy i.e. 4 lines get them clipped as 4 different clips not just one paragraph.


Do you think your workflow can help me? (Red the readme file, think your workflow is more about filtering what is already clipped). 


If not, consider my question as a feature request  :)



My question on Alfred help forum: http://goo.gl/NLnMFH

Link to comment
  • 4 months later...
  • 8 months later...

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