custom tool - Passing selected text to/from ext tools

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
madscijr
Posts: 1
Joined: Wed Jul 22, 2009 3:47 pm

custom tool - Passing selected text to/from ext tools

Post by madscijr »

2009-07-22 Wed

I have been using EditPad Pro 5.x (JG Soft) for many years and developed a number of my own custom tools for it in the form of vbscripts. My workplace however uses TextPad (vrsn 5.2.0) and I would like to set it up to work with some of my scripts. In EditPad you can set up a tool to save the selected text to a temp file then run your script, passing it the temp filename as a command line argument. The script then reads in the file, manipulates the text however you want, and saves it back to the buffer. EditPad then reads the temp file and replaces the selected text with the output of the tool (script). The effect is seamless from the editor.

How would I accomplish the same thing in TextPad? If possible I would like to set the tool up in the same way so both the TextPad and EditPad versions of the tools use the same scripts, so I don't have to maintain multiple versions. However I am not seeing the same I/O options - the closest thing I see for passing a multiline selection to a tool is via the clipboard ($Clip). I tried setting up a tool to copy the selected text to the clipboard this way, then call a "script proxy" (VB EXE I built, as vbscripts can't access the clipboard or some reason I can't currently recall) that receives the vbscript name, saves the clipboard to a temp file, invokes the vbscript, sending it the temp filename as a command line parameter, lets the script finish then reads the script output back from the file & copies it back to the clipboard for TextPad to replace the selected text with, but when I run the external tool, the vb proxy throws an error "Run-time error '5': Invalid procedure call or argument". I seem to have hit a wall with this error currently, and am just wondering if there is an easier way to call my existing vbscripts from TextPad (else I'll just keep plugging on...)     

Any help appreciated...
 
User avatar
trids
Posts: 69
Joined: Wed May 07, 2003 10:16 am
Location: South Africa

Post by trids »

You need to somehow gain access to the clipboard from your script, and then decide whether it's being called from TextPad or EditPad.

I use $Clip to pass multiline selections to scripts written in AutoIt 3, where I save the clipboard to a file and send the results back in a variety of ways depending on the tool - more info on request.

So my recommendation would be to use AutoIt as a wrapper for your vbscript, or instead of vbscript altogether. As a wrapper, you can use AU3 to save the clipboard to a temp file which you can then pass on to your vbscript. And when the vbs has terminated, you can put the results back into the temp file (or whatever).

AU3 is free, is well supported by a user community via a forum like this one, and it is far easier to accomplish more than you can with vbscript. I bet that once you have a taste of AU3 you will want to re-write all your vbs-es in Au3 ... LOL! Meantime .. the wrapper approach will ease you into AU3 and provide you with a workable solution.

Hope this helps :wink:
User avatar
trids
Posts: 69
Joined: Wed May 07, 2003 10:16 am
Location: South Africa

Post by trids »

Another way of doing this with $CLIP (with or without AutoIt) is to use the Unxutils port of to Windows of some brilliant unix file utilities ..
http://unxutils.sourceforge.net/

Just copy pclip.exe from the above collection to your System32 folder (or someplace that's already on your $path). Here's how i use it in my Add-on (a BAT file) to run SQLite3 queries and scripts...

Code: Select all

REM edit mysl3_hdr.sql for any special runtime settings
	copy mysl3_hdr.sql mysl3_script.sql>NUL  
	pclip>>mysl3_script.sql
	echo.>>mysl3_script.sql
	echo.;>>mysl3_script.sql
REM don't forget to specify the correct database here ;o)  ...
	sqlite3 "" ".read mysl3_script.sql"
As a bonus, I'm sure you will find other tools in the Unxutils collection to be just as useful: gclip (pclip's other half), sed, gawk, etc
Post Reply