Saturday, February 17, 2007

Integrating with TextPad

When working with scripts, the most important tool you use is a text/script editor application. From all the ones you can find, and there's a quiet a few, my favorite one is TextPad from Helios Software Solutions. It is powerful and flexible, I just love working with it, my all in one text editor.

I use it for any scripting or text based task, from HTML to PowerShell along with others like [C|VB]Script and many more automation tools. TextPad has everything you need to process and manipulate text. Its great features include the ability to maintain block indents, compare files, automatic code indentation, regular expression based search and replace, macro recording, syntax highlighting, block select mode and much much more.

Additionally, it is lightweight, portable and it's has an unlimited evaluation version (as long as you can bear the nag screen). Among its many features, TextPad has the ability to call external programs (such as compilers).

I'm using it to integrate scripts with their scripting engines, and these days for PowerShell. To integrate PowerShell into TextPad, Run TextPad (Start > Run > textpad) , from the menu choose Configure > Preferences, Click on Tools > Add > Program to add a new program.

 

Navigate to C:\windows\system32\windowspowershell\v1.0 and add powershell.exe, then click the Apply button. You can click the Help button to discover more info on this dialog option, especially on Tool Parameter Macros. Next, click on the plus sign on Tools to expand it and click on Powershell. Review the available options and make them look like:

Click OK to close the Preferences dialog. If you open the Tools menu item you'll see that CTRL+4 was assigned (in my case) to PowerShell, Cool!. Now, that keyboard shortcut can be used to execute *.ps1 files (which you can always change later).

 

But wait, there's more (says Russell Brown). When passing parameters to a script you can use the option to "Prompt for parameters" (second screenshot). This will fire the parameters dialog (each time you'll run a script) where you can add additional parameters. An easier way is to use the $Sel parameter macro. It will send the selected text in the active document (when specified inside the parameters field) as additional parameters (this is limited to the first line in a multiple-line selection).

 

$DOSFile is the same as $File, except that DOS aliases are substituted for any long names in the path, and characters are converted to the DOS (OEM) code set, thus preventing any errors when sending long file names containing spaces. So, from now on, just write the parameters you need inside the script prefixed with the comment sign "#" (to prevent powershell from processing this line), highlight it and press CTRL+4.

 

Behind the scenes, TextPad will create a .BAT file (in the script directory, which you can safely delete) that includes all the parameters and then executes it.

So grab your own copy and start exploring :-)

 

$hay

4 comments:

Anonymous said...

try to use pspad :D

another great programmer editor

greetings

marco.shaw said...

I'm hoping you come back to post some more.

FYI Your blog title with the "$" has caused me some problems when dealing with the RSS feed. Would you consider changing it?

urig said...

Hi Shai. Thank you for this most useful post.

I can add that TextPad supports highlighting PowerShell syntax through files available here: http://www.textpad.com/add-ons/synn2t.html

I also have a question. I'm trying to configure TextPad to run PowerShell.exe with the TFSSnapin. I tried using these as my tool parameters: -PSConsoleFile "C:\Program Files (x86)\Microsoft Team Foundation Server 2008 Power Tools\tfshell.psc1" -nologo -noexit -command ". 'C:\Program Files (x86)\Microsoft Team Foundation Server 2008 Power Tools\TFSS $DOSFile $Sel

and ended up with errors like:
The string starting:
At line:1 char:3
+ . <<<< 'C:\Program Files (x86)\Microsoft Team Foundation Server 2008 Power Tools\TFSS
is missing the terminator: '.


Any idea how to overcome this?

9xcrack said...

reputation for dependability,
TextPad crack 6/