Using KM 7.0.1 / OS X 10.10.4.
I have just started using the Clipboard functions and would like to know if it is possible to search for
-
the tab key; and
-
the enter/return key
in some text placed in the system clipboard?
Using KM 7.0.1 / OS X 10.10.4.
I have just started using the Clipboard functions and would like to know if it is possible to search for
the tab key; and
the enter/return key
in some text placed in the system clipboard?
Hey Victor,
First let’s agree on nomenclature.
I believe what you mean is search for the [tab] and [return] characters within the clipboard — yes?
There are Search and Search & Replace actions for both the clipboard and for variables.
You can search for literal characters by using Option-Tab or Option-Return.
You can use text-tokens to represent those characters:
\t == Tab
\r == Return
\n == Newline
-Chris
Chris,
Thank you. I do mean how to search for a [tab] and [return] characters.
However it is not working for me. I created a test macro with two lines and to search for the return character. But running the macro is not picking up the return. When pasted into TextWrangler there are still two lines (and in TextWrangler I can search for a return (using \r) which is picked up). The macro I created to test search and replace in KM is:
In the search and replace action I tried all 4 options under "using" but none made any difference.
Further help would be gratefully received.
Sometimes the mixed mac OS and Unix pedigree of OS X makes it a bit hard to predict whether lines will be delimited by \n or \r.
(Even less predictable if text is ever coming in from a Windows or an emulator source).
One approach to the regular expression part of this might be to hedge bets and try a regex pattern like:
[\n\r]+
(any sequence of one or more \n or \r)
Hey Victor,
@ComplexPoint's suggestion should do the trick for you.
One of the pitfalls with EOL (end-of-line) characters is that you don't always know what they are.
Classic Mac (CR)
OSX (LF)
Windows (CR-LF)
Sometimes it takes a little detective work to figure this out.
If you're regularly using TextWrangler I suggest you learn a little AppleScript. You can vastly improve the power and reliability of macros that interact with it.
------------------------------------------------------------
# Set the selection (or insertion point if there is no selection) to some text.
------------------------------------------------------------
tell application "TextWrangler"
tell front text window
set text of selection to "Some Text..."
select insertion point after selection
end tell
end tell
------------------------------------------------------------
It's far more organic than driving the UI with KM.
------------------------------------------------------------
# Set a variable to the selected text.
------------------------------------------------------------
tell application "TextWrangler"
tell front text window
set myText to contents of selection
end tell
end tell
------------------------------------------------------------
------------------------------------------------------------
# Set the value of a KM variable via AppleScript.
------------------------------------------------------------
tell application "Keyboard Maestro Engine"
try
set value of variable "myVariableName" to myText
on error
make new variable with properties {name:"myVariableName", value:myText}
end try
end tell
------------------------------------------------------------
# Get the value of a KM variable via AppleScript.
------------------------------------------------------------
tell application "Keyboard Maestro Engine"
if length of (get variables whose name is "X") = 1 then
set myValue to value of variable "X"
else
error "Variable 'X' does not exist!"
end if
end tell
-Chris
Chris and ComplexPoint for your suggestion. Very much appreciated.