I'm a huge Keyboard Maestro fan and I'm hoping that someone can help me with something that seems like it should be very simple. I'm stuck!
I'd like to write a macro to:
Copy text to the clipboard;
Trim leading white space from lines in the copied text;
Paste the text back into the document.
In short, I'd like to turn this:
I would like to trim the white space from the beginning of this line.
I would like to trim the white space from the beginning of this line.
I would like to trim the white space from the beginning of this line.
I would like to trim the white space from the beginning of this line.
Into this:
I would like to trim the white space from the beginning of this line.
I would like to trim the white space from the beginning of this line.
I would like to trim the white space from the beginning of this line.
I would like to trim the white space from the beginning of this line.
However, I'm stuck on step two. I followed the solution described [here] but it does not work.
All it does is insert whatever was resident in clipboard into the space at the very beginning of the paragraph, but it does not trim the leading spaces.
As written, your regular expression removes white-space from the beginning of the string -- and the string is your entire clipboard contents. If you want to remove leading white-space from every line you need to use the ^ anchor and the change the expression's behaviour with (?m) so that anchors match the start and end of lines within your text:
Trim Whitespace removes "leading and trailing whitespace from a string", per the wiki.
So it wouldn't remove any internal whitespace from that text and since there is no leading whitespace and the text wouldn't noticeably change if any trailing whitespace was removed, it appears to do (and may actually be doing) nothing.