September 25, 2006

Macro’d Britney?

Filed under: General — Marcus Tettmar @ 4:44 pm

Every now and then when I’m checking out our web server logs I stumble across an unusual referrer. Today I was surprised to see a referral from a Britney Spears fansite. With a quick glance over my shoulder to make sure no one was looking I clicked the link and checked it out. I discovered a number of forum posts recommending the use of Macro Scheduler for automatically voting for Britney in various MTV music awards! Yes, fans have been creating macros to run for hours on end, submitting votes on the MTV website! I’m not quite sure what to make of it. Am I in some strange, small way, responsible for Britney’s success? In truth I would have thought that MTV would have some way of detecting automated voting, or would discard multiple votes in short succession from the same computer. But who knows? Is Macro Scheduler to thankblame for the state of Teen Pop today?

September 22, 2006

Wwwhy?

Filed under: General — Marcus Tettmar @ 6:55 pm

One of my pet peeves is when I hear newsreaders and TV presenters reading out website addresses and pronouncing the www prefix. Websites actually don’t need the www prefix these days. Reading out www is awkward, and wastes oxygen. Newsreaders don’t need to stumble and stammer over that cumbersome triplet of letters. E.g. if you want to tell people where to find Macro Scheduler just tell them macroscheduler.com. Easy to say and easy to remember.

So my second pet peeve is when I find a website that insists on the www prefix. Luckily they are rare. There’s really no reason why a website should insist on the www prefix at all. So if you own a website, make sure people can view your site without having to type in the www.

That’s all for now. Have a great weekend! 🙂

September 15, 2006

Running UI Automation Routines Concurrently

Filed under: Automation — Marcus Tettmar @ 11:55 am

Macro Scheduler is able to automate other applications by simulating what a user does. There are some exceptions – e.g. it is possible to automate Internet Explorer and Microsoft Office applications through their COM interfaces. But for the vast majority of applications the only way to automate them is by simulating user input and manipulating their UI (User Interface) just as an ordinary user does. Therefore Macro Scheduler has to simulate a human to do what it does best.

Two people would have a hard time trying to use the same PC at the same time. Imagine Fred and Sally sitting in front of the same computer, both trying to use the keyboard at once. Fred is trying to write a letter in Word and Sally is writing an email in Outlook. At the same time. Can you imagine what would happen? Utter chaos is what would happen. Fred opens Word and starts typing. Sally grabs the mouse and opens Outlook. In an instant focus has switched away from Word and Fred’s keystrokes land elsewhere. Outlook hasn’t finished opening yet and for a brief while the Desktop was the active window. Fred’s keystrokes therefore landed on some icons and started opening other applications randomly. Nightmare. Miraculously they manage to sort that out and now Sally has Outlook open as the active window and starts typing. Fred quickly hits ALT-TAB to bring Word back and types some more of his letter. But Sally is still hitting keys on the keyboard so parts of her email end up in Fred’s letter. I think you get the picture. It’s more like a game of “Tug Of War”.

The only way two people could effectively use the same computer is to take turns. Either Fred writes his letter and then tells Sally she can write her email, or, if they want to do bits at a time it might work like this:

Fred: “I’m typing a letter in Word, please don’t touch the keyboard”
Sally: “OK, I’ll wait”
Time Passes
Fred: “OK, I’m done writing in Word for a while, your turn”
Sally: “OK, I’ve activated Outlook. Please don’t touch the keyboard until I say”
Fred: “OK, I’ll wait”
Time Passes
Sally: “OK, I’m done, your turn”

You get the idea. Now imagine that there’s a little red flag on top of the monitor. When Fred starts his letter he raises the flag. When he’s ready and happy to let Sally take over, he lowers it. Sally can now take over, and raises the flag. Essentially they are using a form of semaphore to coordinate their sharing of the computer.

Two Macro Scheduler scripts could do the same thing. Only instead of a little red flag on top of the monitor we could use a value in an INI file, or a registry entry. We’ll call this value RunStatus and it could be initialised to IDLE. Script A needs to focus a window and send some keystrokes to it. It first checks to see if RunStatus is IDLE. If not it waits until it is. It then sets RunStatus to ACTIVE and does what it needs to do before setting RunStatus back to IDLE. Script B meanwhile wants to activate Outlook and click on a toolbar button. It finds RunStatus is IDLE, so waits until Script A has set it back to ACTIVE, and so on. We might put these simple subroutines in both scripts:

SRT>WaitForIdle
  ReadIniFile>ctrl.ini,Share,RunStatus,IsIdle
  Wait>0.2
  If>IsIdle=ACTIVE,WaitForIdle
  EditIniFile>ctrl.ini,Share,RunStatus,ACTIVE
END>WaitForIdle
SRT>SetIdle
  EditIniFile>ctrl.ini,Share,RunStatus,IDLE
End>SetIdle

And then before any part of the script where we need to manipulate the User Interface we can call the WaitIdle subroutine:

GoSub>WaitForIdle

And when we’re done activating windows, or sending keystrokes, we can do:

GoSub>SetIdle

We’ve implemented a very simple form of semaphore for task communication in a multitasking environment. Using this approach we can allow two UI scripts to run concurrently without interfering with each other. If necessary, we can get a bit cleverer. If Script A must perform some automation only after the Script B has completed a specific task, we could create a different flag, or set the flag to a certain value. Script A waits for this value before it can continue.

Clearly it is expensive and wasteful to use one PC for each automation routine you need to run, so solutions like this save money and this is one approach you can use. But depending on the complexity of your scripts you may need to add lots of status checks and pauses. A much simpler solution is to use Virtualization. Install Microsoft Virtual PC, or VMWare and run each automation in its own virtual machine. Effectively you end up multiplexing the physical PC into several virtual PCs and your scripts can run safely in their own virtual machines without interfering with each other.

But on those occasions you need two UI scripts to run at the same time and interact with the same environment, our simple little flag hoisting solution is one you can use. Simple, but effective. But note that at this stage we haven’t considered file-locking and what happens if both scripts read or try to change the flag at exactly the same time. A more robust solution might be to use a value in a SQL database and take advantage of the database’s built in record locking.

A similar approach can even be used to control distributed scripts. With scripts on multiple networked computers, and the INI file in a network share (or using a SQL database), a controlling script can be created which modifies the flag. The networked scripts wait for the active flag before doing anything, and can be paused when the controlling script changes the flag. And flags can be used to synchronize scripts on different machines. This approach has been used successfully in load testing environments where hundreds of Macro Scheduler scripts are simulating tasks simultaneously to create load on the system being tested. You can read more about using Macro Scheduler for automated testing here.

September 9, 2006

September 8, 2006

Word to PDF

Filed under: General — Marcus Tettmar @ 1:46 pm

For Office 2007 Microsoft had been planning to add the ability to output documents to PDF files. Unfortunately Adobe got a bit upset and claimed that Microsoft were in breach of their license to use the PDF format. To avoid costly legal battles Microsoft have agreed to remove the ability for Office 2007 to save to PDF natively, and instead provide the functionality as a plug-in, which Adobe are happy for them to do. So if you have Office 2007 you can download the plug-in for free here.

But what if you aren’t fortunate enough to own a copy of Office 2007 and don’t want to shell out for the upgrade? Well for several years I’ve been using an excellent tool called Win2PDF. It installs itself as a print driver which means you can “print” to PDF from any Windows application. So in Word, for example, you just select File/Print As, choose the Win2PDF driver, enter a filename and you end up with a PDF version of your document. Win2PDF is only $35. I’ve been using it for years and have certainly had value for money from it. And it’s an awful lot cheaper than an Office upgrade too.

You can download a trial version from http://www.win2pdf.com.

September 7, 2006

Vista RC1 Annoyances

Filed under: Vista — Marcus Tettmar @ 11:29 am

Well, after painstakingly working with the Vista UAC team at Microsoft to ensure Macro Scheduler would be Vista compatible, and lots of testing with the Vista betas I was happy to report a while back that Macro Scheduler ran well under Vista beta 2. Recently Vista RC1 was made available under our MSDN subscription so we installed it. Guess what? Well, unfortunately it seems things have changed again and there are now a few things that fail to work under the default restricted user account. I’m pretty sure we just need to make a few tweaks and everything will be hunky dory again in due course. But I’m somewhat annoyed that after our efforts to ensure the software worked with beta 2 it seems lots has changed in RC1.

I’m resisting the urge to turn UAC off. I’m only leaving the default settings intact so that I can be sure Macro Scheduler will install and run under the default configuration. But oh how annoying it is! Try just copying and overwriting a file in the program folder – something power users will do all the time. What a nightmare. Honestly – how many dialogs are really needed for a simple file copy!?

Sometimes I feel like Microsoft’s security philosophy with Vista is analogous to building a house with no doors and windows. Utterly secure and impenetrable but also completely unusable! OK, that’s a bit unfair, it’s more like a door with 15 locks. Very secure, and just about usable … but frustratingly unfriendly!

Update: Ok, I may have ranted too soon. Turns out the problem with Macro Scheduler under Vista RC1 was due to a change we’d inadvertently made, rather than a change in Vista. Looks like we have it sorted!

Get Selected Tab Index

Filed under: Automation, Scripting — Marcus Tettmar @ 6:51 am

As you probably already know, selecting a page of a tab control is usually best achieved by sending CTRL-TAB. So on opening an application we can use the following Macro Scheduler code to jump to the third tab:

SetFocus>Window_Title
Press CTRL
Press Tab * 2
Release CTRL

This issues CTRL-TAB twice and therefore cycles through two tab selections, leaving the third tab selected.

Usually when the window is first opened, the first tab is selected. But what if that is not always the case? How can we determine which tab is currently selected? This question came up in the forum recently.

To do this we can use the Windows API and send the TCM_GETCURSEL message to the tab control. When this message is sent to the control it returns the index of the selected tab.

Here’s an example. Right click on the desktop to open the Desktop Properties dialog and select one of the tabs to change the page. Then run this script:

//Initialise constants
Let>TCM_GETCURSEL=4875

//Get the handle of the Display Properties Window
GetWindowHandle>Display Properties,hwnd

//Find the handle of the SysTabControl32 (Tab Control) object
LibFunc>User32,FindWindowExA,tabctrl,hwnd,0,SysTabControl32,

//Send the TCM_GETCURSEL message to retrieve the selected tab index
LibFunc>user32,SendMessageA,tabindex,tabctrl,TCM_GETCURSEL,0,0

//Display the result
MessageModal>Selected Tab: %tabindex%

This finds the handle of the SysTabControl32 object on the Display Properties dialog and sends it the TCM_GETCURSEL message to retrieve the selected tab index.

You can use this approach with other applications. However, some applications use a different class of tab control, so you’d need to determine the class name of the tab control using the View System Windows tool in Macro Scheduler.

September 4, 2006

September 1, 2006

Do or Die for Windows Vista

Filed under: Vista — Marcus Tettmar @ 10:19 am

According to Sven Hallauer, Director of Windows Release Management, in a podcast interview yesterday, Microsoft has only a couple of weeks to ensure all critical bugs are fixed and in place to meet the Vista deadline. Any delay and the bugs either won’t get fixed, or the release date will slip.

Certainly Vista Release Candidate 1 is much more polished than Beta 2 and it does seem like Microsoft has stepped up a gear to try to meet their target release date.

Listen to the interview with Sven Hallaur in which he explains the build process behind Windows Vista.

August 30, 2006

Success Story – Insurance Company Frontend

Filed under: Uncategorized — Marcus Tettmar @ 6:46 am

This was posted to the forum by Shane this morning:

I have been developing scripts for our Banking and Insurance company for approx 3 years.

We currently have 77 scripts with approx 20 000 lines of code, running on 104 machines and used 11502 times last week by our 100+ consultants.

The scripts are used in our Insurance Call Centre for lodgement of new Home and Motor Insurance claims and for tracking call backs by customers once a claim is lodged. In fact what we have created is like a mini front end for our consultants.

Previously our consultants would lodge claims directly into our Mainframe system. Old style front end, Cobol based, no error checking and no way to ensure accuracy of details.

Now Macro scheduler sits between our consultants and the mainframe and automates many/all of the processes. (completes web pages where required such as booking repairers, emails tow in requests for vehicles, prompts for details such as weather conditions in a road accident, Text messages a customer their claim details at the end of the claim process.)

Reports generated allow us to track why customers call back and how often, how many claims we lodge. I have also combined the reports with information from the Australian Bureau of Meteorology to give us real time tracking of New claim lodgement during storms so we can make predictions on call volumes.

I should also mention that the support we have received from MJTNet is second to none. A great program and a great company to deal with.