I have a fairly simple task I’m trying to automate:
1) copy <text> 2) Find every occurrence in the document of a fixed, reasonably straightforward regex and replace it with <text>.
The point is that I always know where to find <text>, but I don’t know what it says. Doing this by hand is obviously pretty simple, in fact there are two neat ways:
(a) shift-cmd-E on <text> then replaceAll. (b) cmd-C on <text>, then findAll, then cmd-V.
I can’t get either of these to work in a macro.
(a) Seems to fail because the argument to findWithOptions: requires a replaceString. What the macro does is set replaceString equal to whatever value it received (i.e <text>) when the macro was recorded . Removing the line in the macro setting replaceString produces an empty set symbol, which is understandable. (b) Seems to fail because macros don’t like findAll. When I record this operation alone and replay it, all it does is put the caret at the end of the document (the location may be specific to the limited test I’ve done, but the point is I don’t get the multiple carets I should.)
Is there a way of automating this task using macros. I’d much rather not dive into scripting. For example, is there some way to set replaceString equal to the contents of the clipboard?
It doesn’t seem like this should be difficult.
Regards R.
On 9 Jun 2015, at 23:32, Robert Milton wrote:
(a) Seems to fail because the argument to findWithOptions: requires a replaceString. What the macro does is set replaceString equal to whatever value it received (i.e <text>) when the macro was recorded . Removing the line in the macro setting replaceString produces an empty set symbol, which is understandable.
I’ve fixed this for next build, so that if the replace string (or search string) is removed (from the macro argument) then it uses the current value (from the search/replace clipboard).
(b) Seems to fail because macros don’t like findAll. When I record this operation alone and replay it, all it does is put the caret at the end of the document (the location may be specific to the limited test I’ve done, but the point is I don’t get the multiple carets I should.)
The “Find All” action is a standalone action that uses the current search clipboard values. So to make it work for your case, then you would first need to put the search string on the find clipboard (before calling “Find All”), for example via ⌘E or by performing a dummy “Find” (via the dialog).
So the steps would need to be something like:
1. ⌘C (Copy). 2. ⌘F, enter search string, enable regex, and press “Next”. 3. ⌃⌘F (Find All). 4. ⌘V (Paste).
Perfect.
On 10 Jun 2015, at 21:58, Allan Odgaard mailinglist@textmate.org wrote:
On 9 Jun 2015, at 23:32, Robert Milton wrote:
(a) Seems to fail because the argument to findWithOptions: requires a replaceString. What the macro does is set replaceString equal to whatever value it received (i.e <text>) when the macro was recorded . Removing the line in the macro setting replaceString produces an empty set symbol, which is understandable.
I’ve fixed this for next build, so that if the replace string (or search string) is removed (from the macro argument) then it uses the current value (from the search/replace clipboard).
(b) Seems to fail because macros don’t like findAll. When I record this operation alone and replay it, all it does is put the caret at the end of the document (the location may be specific to the limited test I’ve done, but the point is I don’t get the multiple carets I should.)
The “Find All” action is a standalone action that uses the current search clipboard values. So to make it work for your case, then you would first need to put the search string on the find clipboard (before calling “Find All”), for example via ⌘E or by performing a dummy “Find” (via the dialog).
So the steps would need to be something like:
- ⌘C (Copy).
- ⌘F, enter search string, enable regex, and press “Next”.
- ⌃⌘F (Find All).
- ⌘V (Paste).
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate