It's great that I can run an external program on a saved file and capture the output, but it would be even better if I could run a command on a selection instead of the whole file.
I imagine that behind the scenes TextPad could copy the selected text, place it in a new (temporary) document, save the document, run the program on it, capture the output, delete the temporary file, and paste the captured output over my original selection.
Any way to achieve this effect without performing the steps manually?
Run an external program on a selection?
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
How would this macro invoke an external program on my selection?Bob Hansen wrote: Have you considered a macro that would be run after you have made the selection?
I already have a command-line program that does what I want, and it's much too complicated to express as a macro, so I can't convert my program to a normal macro if that is what you are suggesting.
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
I guess I was thinking of something like this:I imagine that behind the scenes TextPad could copy the selected text, place it in a new (temporary) document, save the document, run the program on it, capture the output, delete the temporary file, and paste the captured output over my original selection.
Macro contents:
1. Highlight selection in Doc1, and copy to clipboard. Do not close.
2. Open new Doc2
3. Paste from clipboard
4. Save Doc2 (not really necessary, will be deleted anyway), do not close.
5. Make sure Doc2 is active document and run tool on Doc2 passing filename as parameter.
6. Capture the output in Output Capture Doc.
7. Select all in Output Capture Doc, and copy to clipboard.
8. Go back to Doc1 and paste from clipboard, replacing section which is still selected.
9. Save modified Doc1.
10. Close Doc1.
11. Close/Delete Output Capture Doc.
12. Close/Delete Doc2.
This sounds to me exactly what you have described, you have defined the answer yourself. You can switch between multiple documents in TextPad when recording a macro. Try doing all macro recording with keystrokes, not with mouse.
Hope this was helpful.............good luck,
Bob
Bob
Is the external program able to put its result on the clipboard?
THEN it would be quite easy.
You can run your tool, giving $Sel (or $SelLine or $SelWord) as a parameter. Once the tool has finished (i.e. put the result in the clipboard), you simply press Ctrl-V
I'm not sure whether you can call tools from a macro, but if that is the case, you simply record a macro which invokes your tool and then pastes the result.
THEN it would be quite easy.
You can run your tool, giving $Sel (or $SelLine or $SelWord) as a parameter. Once the tool has finished (i.e. put the result in the clipboard), you simply press Ctrl-V
I'm not sure whether you can call tools from a macro, but if that is the case, you simply record a macro which invokes your tool and then pastes the result.
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
Have you found a solution??
The $Sel parameter macro does not work like you might expect. It only works with the first line of a multi-line selection. This is an understandable limitation, because it is difficult to send a multiple-line blurb of text as an argument to a script or program. You need some way of delimiting that blurb of text as a complete stand-alone unit (not a series of multiple arguments).
I tried using an approach that automatically opens and closes a temp file, but this takes numerous cumbersome steps. The clipboard approach works, but your script must be able to get and set the clipboard contents. It is less work to simply use the clipboard to paste text into and out of another program or script and bypassing the 'tool' menu entirely.
What would make work go *much* faster is if there were a way to export the current selection to a temp file and back into the document with a single keystroke.
I tried using an approach that automatically opens and closes a temp file, but this takes numerous cumbersome steps. The clipboard approach works, but your script must be able to get and set the clipboard contents. It is less work to simply use the clipboard to paste text into and out of another program or script and bypassing the 'tool' menu entirely.
What would make work go *much* faster is if there were a way to export the current selection to a temp file and back into the document with a single keystroke.
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
I suggested a macro earlier that I think does that. You can assign a hot key to the macro and be done with one keystroke.What would make work go *much* faster is if there were a way to export the current selection to a temp file and back into the document with a single keystroke.
Hope this was helpful.............good luck,
Bob
Bob