January 27, 2009

Modal vs Non-Modal – Windows, Not Jazz

Filed under: Automation, General, Scripting — Marcus Tettmar @ 11:07 am

Every now and then, in the forums and in emails to us, there seems to be some confusion over what these terms mean.  As a developer I take these terms for granted, but anyone else, depending on their walk of life, might think they refer to some kind of Modal Jazz; something to do with a modal matrix used in linear algebra; or a type of auxiliary verb used to indicate modality.  

I sometimes need to remind myself that not everyone coming to Macro Scheduler and Windows Automation in general are familiar with geeky software terms.  I can’t tell you much about modal jazz, linear algebra or auxiliary verbs, but I can do my best to set to rest any confusion about Modal and Non-Modal windows.

Modal Windows

When a window is modal it remains active and focused until the user has finished with it and dismisses it.  While it is active no other windows of the same application can be activated.  A modal window is therefore normally a child window.  The user needs to interract with it before control can be returned to the parent application. In effect the parent application is locked and nothing proceeds until the modal window is closed.

You’ll find a good definition of Modal Windows on Wikipedia, here.

Non-Modal Windows

So a non-modal window is the opposite. While it is active you can still activate other windows. The user can switch between windows of the same application. The window being active does not prevent the rest of the application from continuing.

Modal Dialogs

In Macro Scheduler you can create custom dialogs. These can be modal or non-modal to the script. When we refer to a modal dialog what we mean is that once the dialog is displayed, the script halts until the user closes the dialog. Script execution is paused until the dialog is dismissed. The script cannot do any processing while the modal dialog is active. A modal dialog is displayed with the Show command, with a return variable specified, in which the “modal result” of the dialog is reported, corresponding to which button was pressed to close the dialog.

Non-Modal Dialogs

A dialog can be made to be non-modal. In which case the script carries on even after it has displayed the dialog. The user can interact with the dialog while the script continues to perform other tasks. The developer would need to write code to retrieve the state of the dialog and the data that has been entered into it. Usually this would need to take place in a loop. A non-modal dialog is displayed with the Show command, with the return variable omitted. Inside the loop we would retrieve the state and data of the dialog with the GetDialogAction command, and set it with ResetDialogAction.

In this post I have concentrated on definitions rather than going into detail on how you can create and control custom dialogs. That is a subject for another post and you will find more information in the help file and online help. Some dialog examples ship with Macro Scheduler and you’ll find more in the forums.

January 23, 2009

Screen Scraping with Macro Scheduler

Filed under: Automation, General, Scripting — Marcus Tettmar @ 11:50 am

What is Screen Scraping?

Screen Scraping is a term used to describe the process of a computer program or macro extracting data from the display output of another application.  Rather than parsing data from the database or data files belonging to an application, Screen Scraping pulls the data from the screen itself, extracting data that was intended to be displayed to the end-user as opposed to data designed for output to another application or database.  

Screen Scraping is necessary when there is a need to access the information displayed by the application but there is no method provided to access it behind the scenes.  The database or data files may not be accessible, or may be undocumented or proprietary and therefore cannot be parsed easily; the costs associated with interacting with the database may be too high; or the license agreement or warrenty prohibits it.  In the case of legacy systems that are no longer supported there may be no knowledge of the data structures, or the technology used is no longer compatible with current technology.  In these cases we are resorted to extracting the data from the screen – from the windows of the application.

The term Screen Scraping probably originates from the era of computer terminals when you could connect the terminal output of a computer to an input port on another and therefore record the screen data.  

Screen Scraping Methods

There are a number of ways we can retrieve information from the screen using Macro Scheduler, depending on the type of application the data is in.

Screen Scraping Web Applications

Applications like Macro Scheduler’s WebRecorder can access the data and objects inside an Interner Explorer window and can therefore be used to extract the data.  Technically speaking I would not call this screen scraping since WebRecorder is using an API interface provided by Internet Explorer, but the process of extracting information from web sites is commonly refered to as Screen Scraping.  With WebRecorder we can use the ExtractTag wizard to create code that extracts the text from a particular element in the page.   While WebRecorder is the easiest way to do it, it is also possible to automate IE and extract data from web pages by using VBScript. The following forum posts may help:

Automate Internet Explorer with OLE/ActiveX
Automate web forms with IE
HTTP GET and POST using VBscript

Screen Scraping Microsoft Office Applications

Microsoft Office Applications, like Internet Explorer, have a COM interface that allows scripts to manipulate them and access the data held within them.  Again, not really scraping data from the screen itself, as you are getting it directly from a programming interface.    There are a number of examples in the forums and blog archives and also some sample scripts that come with Macro Scheduler which demonstrate how to automate Office applications and retrieve data from them.  

Working with Excel

Screen Scraping Regular Windows Applications

Most other applications don’t offer a scripting interface like MS Office or Internet Explorer.  This is where we really need to work directly with the screen.   There are a number of ways we can do this kind of Screen Scraping with Macro Scheduler.

The Text Capture Functions

Macro Scheduler includes some Text Capture functions which can be used to extract text from a given window, rectangular screen area or screen point.  These functions use low level system hooks which monitor applications calling the various “TextOut” functions that Windows uses to output text to the screen.  By doing so they are able to capture this text.  The Text Capture functions return the text to  a variable which you can then use as needed.  

However, a few applications don’t use the Windows built-in functions to create and output text.  Don’t worry –Most do, but a few use their own techniques.  When you realise that text on the screen is just a sequence of small dots, if the application programmer decided to build his own routine to assemble text from dots rather than calling the Windows functions which already do that for you, you’re not going to be able to capture it.

The text capture functions and their limitations are explained here.  There is an example application, here, created with Macro Scheduler, which you can use to determine whether or not the text you want to capture can be captured using the text capture functions.

http://www.mjtnet.com/blog/2007/12/12/capturing-screen-text/
http://www.mjtnet.com/blog/2008/01/03/screen-scrape-text-capture-example/

Using the Clipboard for Screen Scraping

If the text you want to capture is selectable then you can use the clipboard to retrieve it.  A Macro Scheduler macro can send the keystrokes necessary to highlight and copy the text to the clipboard and then use the GetClipboard function to retrieve that text to a variable.  This is far less elegant than using the Text Capture functions but might be necessary if the application concerned is not utlising any of the Windows text out functions to create the text.

SetFocus>Notepad*
//Select ALL
Press CTRL
Send>a
Release CTRL
//Copy to clipboard
Press CTRL
Send>c
Release CTRL

//Get and display the data
WaitClipboard
GetClipboard>theData
MessageModal>theData

Screen Scraping via Optical Character Recognition

A final resort might be Optical Character Recognition (OCR). If the text is part of an image file neither the Text Capture or Clipboard methods are going to be able to extract it. But, depending on the quality of the image and the fonts used, OCR might. There are a number of OCR engines that can be used by Macro Scheduler, one of which is part of Microsoft Office. The following posts demonstrate how this can be done:

Screen OCR to Retrieve Otherwise Undetectable Text
Screen OCR – Recognising Graphical Text

More on Screen Scraping.

January 22, 2009

Quick Tip: Determine Path of an Application (Update)

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

When using the RunProgram command in Macro Scheduler to run an app you usually need to know the path (unless it’s a system app already in the path) and executable name. Sometimes it’s not obvious what that is. You might start Microsoft Word, or Internet Explorer several times a day without knowing or caring what its exe name and path is. So when you come to write a macro which calls it how do you find out what it is? Well you might think to right click on the application’s shortcut and look at the properties. But this doesn’t always help. If I click on the MS Access shortcut in my Start menu it seems to point to yet another shortcut. I could locate that shortcut and look at that I suppose, but I’m an impatient kind of guy and don’t like being sent around the houses. No, there’s a quicker way:

  • Start the application if it is not already running.
  • Hit Win-R to get the Run dialog and type msconfig32 and hit Enter
  • In the System Information window expand “Software Environment” and click on “Running Tasks”
  • You will see a list of running processes with their Path shown in the second column

Running Task Location

In Vista you can also do the following:

  • Start the application if it is not already running.
  • Start Task Manager (which you can do quickly by right clicking on the task bar and selecting “Task Manager”).
  • Look down the list (you can sort it by name or description) to find the application.
  • Now you can right click on the application’s entry and select Properties and it will show you it’s location. Or right click and select “Open File Location” to see it in an Explorer window.

The location field in the Properties box of Task Manager can be selected, so you can just copy this to Macro Scheduler.

So, even if you don’t know where an application is installed or what its executable name is, it’s easy to find that out once it’s running.

__

Updated 23/01/09 for an XP solution. Thanks to Dick Lockey for pointing out my Task Manager solution was Vista only.

January 21, 2009

Free T-Shirts for Forum Points

Filed under: Announcements — Marcus Tettmar @ 12:13 pm

The forums now let you give points to other users. Reward those that have helped you, and get points for helping out others. And as an extra reward, the top three earners each month will receive a free MJT Net Gearhead T-Shirt (T-Shirts will go to the three people who earn the most points in the proceeding month). For full details see the announcement in the forum. So log in and start sharing your knowledge now.

January 20, 2009

MJT Net T-Shirts and Merchandise

Filed under: Announcements, General — Marcus Tettmar @ 5:03 pm

Thanks to Zazzle we can now offer MJT Net Logo T-Shirts and merchandise.

MJT Logo T-Shirts and Merchandise

Just what every Macro Scheduler user always wanted! View the products at the Zazzle store here. Oh, and by the way – Zazzle are currently offering an “Inauguration Weekend Sale!” which ends today. So act quickly if you want a good deal.

Macro Scheduler 11.1.01 Update

Filed under: Announcements, Macro Recorder — Marcus Tettmar @ 12:02 pm

Macro Scheduler 11.1.01 Update is now available with the following fixes:

– Fixed: Window Open Trigger not working properly when visible windows only is UNCHECKED
– Fixed: Tray icon still not single clicking in Windows 7
– Fixed: Macro recorder “Run this application first” option not working
– Fixed: When entering hotkey via “Type a hotkey” box in macro properties you are not asked if you want to save changes

Registered Downloads/Upgrades | Evaluation Downloads | New License Sales

January 15, 2009

Windows 7 Betta (sic)

Filed under: Windows 7 — Marcus Tettmar @ 4:20 pm

I’m no fish expert, so it meant nothing to me when I saw the pretty looking fish on the Windows 7 beta wallpaper.  Then I saw this CNET report.  Turns out it’s a Siamese fighting fish also known as a Betta fish, pronounced “beta”.  Presumably, therefore, it won’t be the default wallpaper in the final release?

Update: I hadn’t noticed – there are also 7 bubbles!

January 14, 2009

New Linux User Misses Macro Scheduler

Filed under: General — Marcus Tettmar @ 5:57 pm

A while back I got this comment in an email:

“I loved Macro Scheduler. Unfortunately, I’m now working exclusively on Mac and Linux boxes. I have kept a copy of Macro Scheduler, just in case I ever return to Windows, and have recommended it to many friends (2 of which have purchased copies).  After 2 years without Windows, I have to say that I don’t miss Windows, but I do miss Macro Scheduler.”

Despite the fact that we’ve lost a customer to Linux, I think that’s quite an endorsement. Linux has always catered to the sysadmin with its rich command line interface, and all Linux tools, utilities and system apps provide a command line processor. Linux also comes with a number of built-in scripting languages and an advanced scheduler called Cron. So Linux is made for being automated. Windows, on the other hand, was designed almost exclusively for human users and is purely graphical. Therefore, tools like Macro Scheduler are required to automate Windows applications. Nice to hear how important Macro Scheduler was to this sysadmin when he had to put up with Windows 🙂

January 12, 2009

Macro Scheduler 11.1 Update

Filed under: Announcements — Marcus Tettmar @ 12:25 pm

Macro Scheduler 11.1 Update is now available with the following fixes:

– Fixed: Text Capture functions (GetWindowTextEx, WaitScreenText, GetTextInRect, GetTextAtPoint) could
cause clipboard function to stop working in source application
– Fixed: Standalone Editor not prompting to save on exit after compile options changed and not saved
– Fixed: Inline Function selector not adding chevron to GetWindowList
– Fixed: Updating dialog in editor from popup menu could leave blank space at start of first line of dialog block
– Fixed: Find Next in Editor will now follow search direction as set in Find dialog
– Fixed: Tab characters causing text loss in watch list
– Change: Tray icon action changed to single click for Windows 7

Registered Downloads/Upgrades | Evaluation Downloads | New License Sales