I found a way to select something - calculated on run-time - by using a normal macro (plus command) without TMTOOLS!!
The problem was if I have a script which outputs a text chunk or a regexp how can we select that text/regexp in a TM window? The approach is actually very simple. I copy the text/regexp into the shared find pasteboard; place the caret to a proper location; and execute 'findNext'. Thus I wrote a tiny C program which copies a string into the shared find pasteboard. OK, then I wanted to write a man page for that command on basis of the normal pbcopy man page, and I figured out that pbcopy is already able to do this ;)
Fine. The only problem was that if I write a tmcommand à la:
echo -en "FINDTEXT" | pbcopy -pboard find
it doesn't work because "pbcopy -pboard find" is called from inside of TM. If I execute that in a Terminal, switch back to TM it works. The solution: I have to execute this in a new bash environment.
The basic tmcommand (example name "SELECTTEXT"):
RESULT=$(A SCRIPT WHICH RETURNS A TEXT OR REGEXP) export RESULT /bin/bash -c 'echo -en "$RESULT" | pbcopy -pboard find' #place the caret to a proper location to be able to execute 'findNext'! open "txmt://open/?line=$LINE&column=$COLUMN"
After executing that command the string $RESULT is in the shared find pasteboard, and the caret is set.
Next step > the macro: Before we can execute 'findNext' (= APPLE+G) we have to set the parameters of the find panel, meaning whether we want to do a regexp search or not; ignore case or not.
Thus record a macro à la:
1) open find panel, set the desired parameters, and do a dummy search for something which is NOT in the document -e.g. look for \xFFF3; and close it
2) execute the command "SELECTTEXT"
That's it. The nice side-effect is that the macro changes nothing within TM's find panel ;) And the macro does not affect the undo buffer, it does not change the text etc., and the selection is done instantly.
But attention: The only tricky point : Be aware of correct escaping!!
On that basis I wrote the "Select XML/HTML balanced tags" script which will come as soon as possible. I only have to fix some tiny things.
To minimize the escaping one can use:
/bin/bash -c 'echo -n "$RESULT" | pbcopy -pboard find'
/bin/bash -c 'echo -en "$RESULT" | pbcopy -pboard find'
To get rid of the utf8 encoding one can use:
/bin/bash -c 'export __CF_USER_TEXT_ENCODING=0x1F5:0x8000100:0x8000100;echo -n "$RES" | pbcopy -pboard find'