Jump to content
isometry

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

 

Robin

Edited by isometry

Share this post


Link to post

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.

Share this post


Link to post

Added support for command aliasing: alias commonly used one-liners to one-word aliases.

 

| alias myalias=arbitrarily -complex | pipeline@@
| myalias

| alias lc perl -nle 'print lc'@@
| lc 
Edited by isometry

Share this post


Link to post

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

Share this post


Link to post

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

Share this post


Link to post

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

Share this post


Link to post

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

Share this post


Link to post

This is brilliant for more than one reason. 

 

I'm going to get loads of use out of this. And it looks like I'm going to get a whole new perspective on scripting, too.

 

Thanks very much!

Share this post


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.

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