I have the following function in AutoHotkey that attaches the strings Left
and Right
as a prefix and suffix to a given text string that is pre-selected on a text file:
TagWrapper(Left, Right)
{
ClipSaved := ClipboardAll
Clipboard =
send ^c
Clipboard = %Left%%clipboard%%Right%
send ^v
Clipboard := ClipSaved
ClipSaved =
}
The function works by copying the text into the clipboard, and then adding the prefix Left
and suffix Right
to it.
Now, I would like to add line breaks between Left
and clipboard
and also between clipboard
and Right
so that the text is wrapped between two lines with contents in Left
and Right
. How can I do this?
I have tried adding
`n
or
`r
between the prefix and suffix and the clipboard, e.g. as follows :
TagWrapper(Left, Right)
{
ClipSaved := ClipboardAll
Clipboard =
send ^c
Clipboard = %Left%%`nclipboard`n%%Right%
send ^v
Clipboard := ClipSaved
ClipSaved =
}
but that didn't work (the script can't even run). Any thoughts?
Best Answer
You need to move the middle 2
%
characters in the following, so that they are next to the clipboard. (You seem to have inserted the ```n`` in the middle of the%clipboard%
)i.e. this would be an improvement:
If this still doesn't work, then there is a specific example in the AutoHotKey Tutorial and Overview that talks about using ```r`n`` to add both carriage return and linefeed.
(Depending on which platform you're on, text files will have different line endings: see The Great Newline Schism)