vbScript – Extending Application Functionality with vbScript and AutoIt

vbScript - Extending Application Functionality with vbScript and AutoIt

Sometimes you'll find that one of your favourite applications is missing some useful functionality. For me, it was FastStone Image Viewer. I've had to scan a large number of family photos to convert everything to digital. Rather than scan one photo at a time, I found it faster to fill the scanner and scan an entire page at once. That reduces the overall scan time but it means that I have to crop and save each individual photo from the gang scans.

FastStone has a crop board where I can select an area and Lossless Crop To File. Unfortunately, it autogenerates the file name by appending _cr to the current file name, so each succeeding crop to file overwrites the previous.

Using a free third party package, AutoIt and vbScript I can add the functionality.

The first step is to run the included tool, AutoIt Windows Info. Once this is running I then run FastStone, invoke the crop board, select an area, and choose Lossless Crop to File. I then select the control which contains the file name. The AutoIt tool tells me that the control name is Edit1.

Now, using the AutoItX component of AutoIt I can create a vbScript module that will run continuously in the background (but only when I need to do a lot of cropping). This script will continuously loop and watch for the creation of a window with the title Lossless Crop to File. It will then calculate a new file name for the cropped portion and save it. The script will then go into a pseudo wait state (using sleeps) until the next crop request appears.

This is not nearly as elegant as coding with REXX ports on the old Amiga (they were awesome) but it is still highly useful.

Note that sleep states and loops may be required to wait for controls to respond to commands.

Using the same technique I was able to automate the optimum pension split calculation in the program I use to file my income tax, a very tedious task if done manually.