February 23, 2007

Remote Citrix Automation the Easy Way with AppNavigator

Filed under: Automation — Marcus Tettmar @ 8:36 pm

In my last post I showed you how to write an Image Recognition script in Macro Scheduler to automate a remote Citrix session. I demonstrated how to use Image Recognition functions to look for screen objects and create an Outlook email.

Well, in this demo I show you how to automate the exact same process using AppNavigator. The video is just over two minutes long and that includes the time taken to build the routine and play it back! You can see that there is no coding involved. Anyone who knows the process could create the routine.

Watch the video and compare to building the same process with code.

This is a very basic example where all we do is create an email. In the real world we’d take it further and we may also want to add failover checks to handle situations where window objects fail to appear or change. With the first solution we’d need to modify the code to handle this and our script would become much more complicated. With AppNavigator it would be a simple case of adding a not found action to the relevant images. We could tell it to try again, stop, jump to a different image, send an email (with a screen shot) to admin, run a script … etc. Maintenance becomes so much easier and less prone to introducing bugs compared to modifying long scripts of code.

February 20, 2007

How to Use Image Recognition

Filed under: Automation, Scripting — Marcus Tettmar @ 12:11 pm

What is Image Recognition?

Update. Image Recognition has been vastly improved and simplified since this article was written and in v13 we introduced an Image Recognition Code Wizard. Watch this video to see how simple it is.

Image Recognition allows Macro Scheduler to find a bitmap (needle) in another, larger, bitmap (haystack) and return its position. The larger bitmap could be a snapshot of the screen, and the smaller bitmap could be a capture of a toolbar button or some other screen object. Therefore Image Recognition allows us to locate objects on the screen, graphically. We can also wait for images to appear on the screen. So Image Recognition allows us to automate any kind of graphical interface. We can make the script wait for images to appear on the screen, find screen objects and therefore send mouse events to the correct part of the screen to focus or control the objects.

The functions most used for Image Recognition are as follows:

WaitScreenImage
FindImagePos
GetScreenRes*
ScreenCapture*

*Note: GetScreenRes and ScreenCapture are no longer required (since v9.2) as you can now specify SCREEN for the haystack in FindImagePos

Building an Image Recognition Script

In this video I demonstrate the Image Recognition functions to automate Outlook running in a remote Citrix session. Traditionally automating interfaces in remote environments is difficult without having Macro Scheduler running on the remote server. Trying to automate a remote desktop with traditional commands is unreliable since the client doesn’t know anything about the windows and objects running on the remote server – all it sees is a graphical copy of the screen. This is why image recognition is so powerful in such situations.

Watch the video and then continue reading this article to learn how the script works.

In the video I first tell Macro Scheduler to find the position of a button on the screen. I first want the macro to find this button:

New Email Button

First I use the image capture tool to capture an image of this button from the screen and save it to a .bmp file. The image capture tool is available in the editor under the Tools menu, and also from the Capture button on the Command Builder dialog for the FindImagePos and other image recognition functions. I save the image to d:\citrix-images\new2.bmp.

The first thing I need my script to do is determine the dimensions of the screen. This is so that I can capture the entire screen later in the script. So I use the GetScreenRes function:

GetScreenRes

This returns the width and height of the screen in variables sX and sY. Next we capture the current screen to d:\screen.bmp using the ScreenCapture command:

ScreenCapture

So this captures the entire screen, from 0,0 to sX,sY returned by GetScreenRes.

Note: Since version 9.2 the above two steps are no longer necessary as it is now possible to specify SCREEN in FindImagePos and do not have to first copy the screen to a bitmap

Now we want the script to look for the new email button in this screen image using the FindImagePos function. This looks like this:

FindImagePos

This looks for new2.bmp inside screen.bmp using a color tolerance of 20 (where 0 is not tolerant and the pixel colors must match exactly and 255 is highly tolerant and anything would match!). We set the fourth parameter to 1 to tell it to return the center coordinates of the image match. If this was zero it would return the top left position in screen.bmp where a match was found. But I would like to return the coordinates of the center position of a match. i.e. the center of the new email button on the screen. XPos and YPos are our variables the coordinates will be stored in. These are arrays. So the first match will be in XPos_0,YPos_0, the second match (if any) in XPos_1, YPos_1, etc. imgs is the return variable which is set to the number of matches found.

So now we can say “if a match was found, move the mouse to the first position and click”. This looks like:

MouseMove

Since we captured the entire screen, the coordinates returned by FindImagePos map directly to screen coordinates. If the ScreenCapture command had not captured the entire screen we would have to add the top x,y coordinates given in the ScreenCapture command as offsets to the MouseMove command. As we captured the entire screen x,y was 0,0 anyway. Sometimes it is not necessary to work with the entire screen and we could instead capture just a Window. Like this:

MouseMove Relative

One would then have to add X,Y to any position returned by FindImagePos in order to map to an absolute screen position.

But back to the demo. We now have code which finds the new email button on the screen and clicks on it. This causes a new window to appear. If we were automating an application running on our desktop we could simply use the good old WaitWindowOpen command which is given the window title and waits for that window to appear. But, remember, this demo is automating a remote environment. The windows are on another computer. We don’t know about window titles. Citrix just sends us an image of the screen of the remote computer. So instead we will use the WaitScreenImage function. This is nice and easy:

WaitScreenImage

I used the capture tool to capture an image of the top left part of the new window – showing the window icon and title:

Window Title

That was saved to title2.bmp. So the above function simply watches the screen and waits until it finds this image on the screen. When that happens we know the new window has appeared.

By the way, you could create your own WaitScreenImage using a loop containing ScreenCapture and FindImagePos. This would give you more control and build in a timeout if required. But WaitScreenImage is a quick and easy way to wait for an image to appear on the screen without any further coding.

Finally, now the script knows the new window is present it can send some keystrokes, so we send some text to create the email. In the real world we’d probably use more image recognition to manipulate other objects on this new window and continue using the same techniques.

send keystrokes

Tips

For performance reasons the image recognition functions do not check every single pixel in each image. That would take far too long. Instead a random sample of pixels is taken from the small “needle” image and each of these is checked against all the possible matching pixels in the larger “haystack” image. For this reason it is possible to get false positives if the image you have captured is not very specific. E.g. consider these two images:

done

connecting

These images are largely similar since we have too much gray area. If the random sample is all from the gray area both would match. These are from a status bar, and if we were searching for Done we could easily find Connecting. The solution here is to make the image smaller so that there is less of the gray background. Alternatively find something more specific on the screen.

Note: You can override this behaviour by setting the number of pixels to scan using the FIP_SCANPIXELS variable, and since v12 this can be set to ALL to perform an exhaustive match and tests reveal no noticeable performance hit in doing so.

AppNavigator Does it Without Code

AppNavigator takes all the coding away from image recognition and also adds some more power. It is clever enough to narrow down a search if it first finds too many matches, or none at all, and it also remembers the part of the screen a match was found in. Next time it will concentrate on that part of the screen and only search the entire screen if a match is not found. This increases performance and reliability. With AppNavigator you can capture screen objects and assign them actions without having to write code like that presented here. AppNavigator can be told what to do when an object can’t be found, and can also navigate the extraction of data from Excel or Access without coding that either.

To see how easy it is to create the same process with AppNavigator see my next post.

Update 12th October 2007: Macro Scheduler 9.2 (and above) now lets you specify SCREEN in the haystack parameter of FindImagePos. Therefore if you are scanning the entire screen you no longer need to use GetScreenRes and ScreenCapture to capture the screen to a bitmap file first. Just specify SCREEN in FindImagePos.

February 9, 2007

New Direct Access Beta

Filed under: General — Marcus Tettmar @ 12:09 pm

There’s a new beta version of Direct Access available from our friends at Nagarsoft. Regular readers will probably know how much I love this productivity tool. Direct Access lets you define keyboard abbreviations for commands, applications and folders etc. Once an abbreviation is set up you can type it wherever you are, whatever application is active. It’s great – I no longer wade through long lists of shortcuts in my Start menu, and I no longer have to switch from my open windows to the desktop and scan through desktop icons. All I do when I need to start something, or open my Documents folder is type in the abbreviation and hit F12. Doesn’t matter what window happens to be in front of me. It works like a dream. And it complements Macro Scheduler nicely too. I have a number of important macros that I run several times a day. With them set up to run from a Direct Access abbreviation I just type the macro name on my keyboard and it fires up. Really very handy.

Nagarsoft want your feedback on this new beta. Details here. This version is fully compatible with Microsoft Vista.

And don’t forget that Macro Scheduler customers can get 25% off Direct Access. Log into your account to get a coupon code and find out more.

February 8, 2007

Skunkworks = Paul

Filed under: Announcements, General — Marcus Tettmar @ 3:02 pm

Some regular mjtnet.com forumites may have noticed that forum member SkunkWorks has recently become pgriffin. For those of you that don’t know, Skunkworks, according to Wikipedia, “is a term used in engineering and technical fields to describe a group within an organisation given a high degree of autonomy and unhampered by bureaucracy, tasked with working on advanced or secret projects.” Yes, SkunkWorks is actually none other than our very own Paul Griffin.

Paul started using Macro Scheduler some years ago as a customer of ours and has become a bit of an expert. For the last few years he has specialised in providing Macro Scheduler consultancy and has made his living from developing Macro Scheduler code for his clients. Under his SkunkWorks persona he has been active in our forums, providing help to other members. About a year ago Paul joined us to help out with customer support. About that time Paul had the idea for AppNavigator, and the SkunkWorks operation began developing in earnest. As you probably know from recent announcements, AppNavigator was officially unveiled a few days ago.

So Paul is now VP for AppNavigator and has cast off the SkunkWorks forum persona. So for all you forumites, pgriffin = Skunkworks. And congratulations to Paul for the official launch of AppNavigator!

February 6, 2007

Buying Macro Scheduler in Romania

Filed under: General — Marcus Tettmar @ 12:08 pm

Did you know it is now possible to purchase Macro Scheduler in Romania? Selling software in some Eastern European countries is difficult for two main reasons:

1) The local USD exchange rate means the regular USD price is much more than most can afford.
2) Credit card penetration is low.

These factors have lead to a high rate of piracy in places like Romania, where people either cannot afford, or simply don’t have the means to pay for software.

So we have teamed up with SoftMall.ro to sell Macro Scheduler in Romania. They are able to take local payment methods and Macro Scheduler is available from SoftMall.ro at 49 RON which equates to approximately $20 USD.

January 19, 2007

AppNavigator – Point and Click Enterprise Automation

Filed under: Announcements, Automation — Marcus Tettmar @ 3:07 pm

AppNavigator is a powerful new tool that lets you create automation routines graphically, without any need to write code. With this software you can create processes by highlighting screen objects and assigning actions to them. Any process can be automated based on simple graphics – by “seeing” the screen. Just show AppNavigator what to watch for, and what to click on, and build up a process based on visual cues. You can read more information here. We also have some Flash video demos available:

Creating an AppNavigator Process
Playing back an AppNavigator Process

January 11, 2007

Restart Aero Glass

Filed under: Vista — Marcus Tettmar @ 2:56 pm

Sometimes Vista appears to lose Aero Glass. Aero Glass is the fancy effect that gives windows a semi-transparent border and adds a certain gloss to the desktop. Purely aesthetic but very pleasing. But very occasionally my screen flickers and then Aero Glass gets disabled. I’m not sure why – my best guess is the memory somehow gets maxed out so Vista downgrades the display. Trouble is it doesn’t come back again automatically. I’ve always had to reboot the machine, which is annoying. But I’ve just discovered this little trick to get it back: Stop and restart the “Desktop Window Manager Session Manager” service using these commands in an elevated DOS prompt:

net stop uxsms
net start uxsms

And back comes the lovely shine! 🙂

January 3, 2007

2007 – 10 years of Macro Scheduler!

Filed under: General — Marcus Tettmar @ 3:23 pm

MJT Net Ltd, and Macro Scheduler, will be 10 years old this year. The company was officially incorporated on 15th August 1997, though Macro Scheduler itself was launched sometime in March. So 2007 will be a special year for us. When I first created Macro Scheduler back in 1997 I never imagined that it would evolve into the product it has become. The evolution of the product is largely thanks to the many wonderful users who have always offered valuable suggestions and ideas for new features. Development has always been extremely user-driven and here we are today with a superb product I can be very proud of. So, many, many thanks to everyone who has contributed with suggestions and feedback over the last ten years. It has been an amazing ride. Thanks to all who have contributed to our success so far with your custom and loyalty.

Here’s to another ten years, and more, of Macro Scheduler!

January 1, 2007

December 11, 2006

Works with Vista – Official

Filed under: Vista — Marcus Tettmar @ 2:17 pm

Works with Windows Vista We’ve recently entered the Microsoft Windows Logo Program and just obtained the Works with Vista logo for Macro Scheduler 9.0 🙂