Jump to content

Clipboard: Strip whitespaces on copy or paste


olfway

Recommended Posts

Thanks for your suggestions!

If I understand correctly then I have two options with workflows – run workflow for copy to clipboard or run workflow to paste, right?

 

If I would run workflow to paste then I'll miss alfred's clipboard history viewer, so that's not an option

 

So it seems the only way I can use it – create a workflow to get current selection, strip whitespaces from it and paste it to clipboard and assign it to cmd+c hotkey

But there will be a problems here – sometimes I want to copy images or files and sometimes I copy via menu instead of hotkey and sometimes iTerm itself copies selection to clipboard

 

Probably if Alfred would have a trigger like "text content copied to clipboard" and output like "replace content in clipboard history" then I would be able to make a workflow which would work.

 

But actually I think that whitespace trimming is so basic feature, so it could be added as a feature to alfred's clipboard manager itself

Link to comment
Share on other sites

Although it's not exactly what you want you may find this Alfred help page useful: Using Clipboard History Items In Workflows and Snippets.

 

It would, for example, allow you in a workflow to recall the last item pasted to the clipboard and strip whitespaces, etc., in the workflow before pasting.

 

I appreciate that you will say the problem is that you may not know the position on the clipboard of the item you need but I thought it worth pointing to the help page nevertheless.

 

Stephen

Link to comment
Share on other sites

17 minutes ago, olfway said:

Thanks for your suggestions!

If I understand correctly then I have two options with workflows – run workflow for copy to clipboard or run workflow to paste, right?

 

If I would run workflow to paste then I'll miss alfred's clipboard history viewer, so that's not an option

 

So it seems the only way I can use it – create a workflow to get current selection, strip whitespaces from it and paste it to clipboard and assign it to cmd+c hotkey

But there will be a problems here – sometimes I want to copy images or files and sometimes I copy via menu instead of hotkey and sometimes iTerm itself copies selection to clipboard

 

Probably if Alfred would have a trigger like "text content copied to clipboard" and output like "replace content in clipboard history" then I would be able to make a workflow which would work.

 

But actually I think that whitespace trimming is so basic feature, so it could be added as a feature to alfred's clipboard manager itself

Unless I am misunderstanding something these actions should still be in your clipboard unless you check "mark transient in clipboard" in the "copy to clipboard" object. if you copy or paste in frontmost app they should still stay in your clipboard after you paste. In my screenshot below, my actions for Reverse Line Order and Shell Escape Text both remain in the clipboard after pasting in the front most app.

 

image.thumb.png.0c03b39f36102659f0be898a09d4b49a.png


 

Link to comment
Share on other sites

If I understand correctly – I could create an universal action like "Paste with stripped whitespaces" and then select it from history viewer or run it with some special hotkey, right?

 

That's probably would work but that's too many actions for this task, I just want to press cmd+c, cmd+v or select from history viewer and always have it pasted with stripped whitespaces

 

For other text manipulation like lowercase, UPPERCASE and so on it's really useful I will certainly use it, thanks!

Link to comment
Share on other sites

36 minutes ago, olfway said:

and assign it to cmd+c hotkey

 

Don’t do that (also, Alfred won’t let you) because Alfred relies on it to copy (there’s no universal way to copy something from every app, so that’s the way it needs to happen).

 

Taking from the excellent suggestions by @sepulchra and @Stephen_C, you can have a Hotkey Trigger with macOS Clipboard Contents and Transform it to trim it. By adding an Arg and Vars Utility with a {clipboard:N} dynamic placeholder you can even directly paste a specific entry. With a Universal Action you can do it from the Clipboard History.


What you can also do is have a Hotkey Trigger with Selection in macOS connected to the Transform, connected to the Copy to Clipboard Output. That way when you’re looking at the item in Clipboard History, you press the new shortcut and have it paste trimmed. And with that and the first Hotkey, you have both situations covered with one Hotkey each (instead of ⌘V).


There’s also a Trim Line Whitespace Automation Task which can trim from every line (as the title says instead of just from the whole text. Some times that’s what you want, sometimes, not, there are many options!

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