Share |

Marcus' Macro Blog

Mostly tips, tutorials, articles and news about Macro Scheduler & Windows Automation

Archive for 2010



Support Email Rant

Tuesday, November 23rd, 2010

I received the following email today (I have paraphrased and anonymised it to protect the innocent):

“We were given a Macro Scheduler script to run on our system that someone else wrote which we are trying to use with your trial version. It doesn’t work. Your product seems to be very flaky and unreliable. Is this a feature of the trial version?”.

Now, when I read an email like that I have to breathe carefully and compose myself. To see what’s wrong with it let’s reword the same message as if it were talking about a different product:

“We were given a VBScript file which someone else wrote and we are trying to run it on our system but having problems. Microsoft VBScript must be very buggy!”

Yeh, so because a script that someone else built using a particular product is buggy the user thinks it is the product that is buggy. It seems not to have occurred to them that the script they were given is clearly not put together very well, or at least not written to run on their system. It hasn’t crossed their mind to report back to the person who wrote the script. For all we know the person who wrote it never intended it to be run on any other system but his/hers anyway.

You can build all kinds of dodgy, bug-ridden and dangerous software with C++. Does that mean Microsoft Visual Studio has a bug?

I’ve downloaded lots of dodgy VBscript code snippets, buggy PHP files and Perl scripts that fail to do what the author says they do, or need tweaking to work on my system. It never occurred to me to blame the VBScript, PHP or Perl interpreters. Next time rather than email the author of the code I’ll email Microsoft, PHP.com or Larry Wall instead.

Sheesh.

WebRecorder Update

Thursday, November 18th, 2010

WebRecorder and the IEAuto runtime have been updated as follows:

IEAuto 2.08 :

  • Added the ability to specify classname for ClickTag
  • Fixed issue where some fields may not click in IE8/9

WebRecorder 2.4:

  • Added Name/ID to Tag Extraction Wizard and will now output an ExtractTagByName if an ID or Name is present
  • Workaround for pre-focused fields to ask user to mouse click in element to identify it
  • Added detection of classname for ClickTag
  • Fix for situation where a form has no name (was previously returning [Object])
  • Removed old tag extraction drop down from toolbar and added Tag Extraction Wizard button

Registered Updates | Trial Downloads

Video Tutorials Needed – Make A Video!

Wednesday, November 17th, 2010

We need to add more video tutorials. There are thousands of forum posts, blog posts and articles on this site but so far we’re shamefully low on video tutorials.

So I need your ideas. I’m not very good at coming up with contrived examples and I’m also the kind of person who learns by doing, so perhaps that’s why I struggle to come up with training guides and videos.

So, you can do one of two things:

1) Send me your ideas for a video. Don’t be too vague. Videos need to be short, so it needs to be fairly specific. Saying “Do a video on dialogs” is not that helpful. Which bit of dialogs? But remember that not everyone has the same applications, so any example needs to be reasonably generic. I can’t do a video on “automating SAP” for example. That’s actually TOO specific.

OR

2) Create a video yourself! All you need is the free version of Jing and a microphone. Assuming we think your video is appropriate we’ll put it on our site on the video tutorials page with your bio and web link if you have one (so you can promote your services if appropriate). We’ll also reward all contributions with free licenses/updates. You could even make a name for yourself!

Email me your ideas or contributions here.

Creating Native Function Aliases for Win32 Functions

Monday, November 15th, 2010

The other day I posted a response on the forums which uses LibFunc to run the Win32 API function GetKeyState. This prompted someone to email me the following:

I didn’t know the Win API call to check for a key being down. The API call works but have you considered adding a native MS command called KeyDown> or maybe CheckKeyDown>

Well, it’s already possible to create native looking functions for DLL functions and therefore Win32 API functions.

We can do this by creating an Imports file in the Imports sub folder of Macro Scheduler. Let’s make an import file for some functions in User32.dll:

Step 1. If you don’t already have an Imports subfolder inside the Macro Scheduler program folder, create one: c:\program files\Macro Scheduler12\Imports

Step 2. Create a symbolic link to the appropriate DLL in this folder. Start a CMD prompt and CD to the Imports folder and for User32.dll type the following:

mklink user32.dll c:\windows\system32\user32.dll

If on a 64 bit system replace system32 with syswow64

This will create a link to the DLL in the Imports folder. Next we need to make a corresponding INI file.

Step 3. Create a file called User32.ini in the Imports folder. Inside this file create entries for each function you wish to import. E.g.:

[GetKeyState]
FunctionName=GetKeyState
Parms=1
Parm1=INT

[SendMessage]
Parms=4
Parm1=INT
Parm2=INT
Parm3=INT
Parm4=INT

[FindWindow]
Parms=2
Parm1=PCHAR
Parm2=PCHAR

Now, instead of writing:

Let>VK_UP=38
LibFunc>user32,GetKeyState,result,VK_UP

You can write:

Let>VK_UP=38
GetKeyState>VK_UP,result

So here’s a project for someone or a group of people: Create a User32.ini file for a fuller list of compatible functions which we can share on the website. Any function that accepts either integers (INT) or strings (PCHAR) and returns an integer (or nothing) can be included. And then we want another one for Kernel32.dll … etc.

Macro Scheduler 12.1.1 Available

Monday, November 8th, 2010

Macro Scheduler 12.1.1 is now available with the following fixes since my last update announcement:

  • Fixed: TrayIcons, XL, Telnet and ADO objects being destroyed at end of event handler subroutines
  • Fixed: FTP Status window in FTPDelFile, FTPRemoveDir, FTPMakeDir, FTPRenameFile not being closed at end of operation
  • Fixed: A macro containing a dialog called with the Macro> command will not show the dialog

Workflow Designer and the SDK have also been updated to the same MacroScript version.

Registered Downloads/Upgrades | Evaluation Downloads | New License Sales

Is a File Ready? Waiting for a File Process to Complete.

Wednesday, November 3rd, 2010

In the comments to my last post Richard asked how we can wait for a process to finish updating a file.

In my reply to Richard I point out that most of the time we can use a visual cue. Where possible this is the approach I would use. Usually an application would present some kind of visual cue when the file operation finishes. A dialog box might appear, or disappear, an object may become enabled or disabled, some text may appear on the screen, etc. We might be able to use commands such as WaitWindowOpen, WaitWindowClosed, WaitWindowChanged, WaitScreenText, WaitScreenImage, WaitCursorChanged, WaitPixelColor, or WaitRectChanged. Or we might even create our own wait loop which checks for some value or property. I mention this approach in Top Tips for Reliable Macros.

Unfortunately there are sometimes scenarios where there is no visual cue and we have nothing we can “see” which tells us the file operation has completed.

If the file is locked by the application that is writing to it, we could create a wait loop which checks to see if the file is still locked or not.

How might we achieve that? Well, why not just try to read from the file. If the file is locked we’re not going to be able to read it right? So we could just do:

Label>wait_file
ReadLn>file,1,res
Pos>##ERR##,res,1,pErr
If>pErr>0
  Wait>0.2
  Goto>wait_file
Endif

This will work for any kind of file.

Of course this assumes that the file is locked for reading by other processes.

It’s possible that the application locks the file only for writing. In that situation we could use WriteLn to attempt to write an empty string to the file:

Let>WLN_NOCRLF=1
Label>wait_file
WriteLn>file,res,{""}
If>RES<>0
  Wait>0.2
  Goto>wait_file
Endif

But that’s a bit invasive in the instance that the file IS available as although we’re writing nothing, we’re still modifying it so updating it’s timestamp.

We can get a bit more control over this with VBScript where we can attempt to open a file for appending without actually modifying it:

VBSTART
Function TestFile(filename)
   Set oFSO = CreateObject("Scripting.FileSystemObject")
   On Error Resume Next
   Set f = oFSO.OpenTextFile(filename, 8, True)
   TestFile = Err.Number
End Function
VBEND

Let>file=C:\files\bmp.bmp

Label>wait_file
VBEval>TestFile("%file%"),fRes
If>fRes<>0
  Wait>0.2
  Goto>wait_file
Endif

All the TestFile function does is try to open the file for appending, and if an error occurs it returns the error code. So if we get zero back, there’s no error and the file must be available for writing and therefore not locked.

Don’t be put off by the fact that this uses the OpenTextFile method. It will still work with any kind of file. We’re not actually going to attempt to modify it. We’re just trying to see if we can open it. So the file type is unimportant.

Note that in these samples I haven’t checked for any specific error code nor have I checked for the existence of the file first – I’m assuming any error means the file isn’t available. An error will also be returned if the file does not exist, so you’d probably want to use IfFileExists first. You might even want to put FileExists in a loop so that you can wait until it exists.

Note also the small wait in each loop. This is just to make sure the loop isn’t so tight that it hogs CPU. Better to be nice to the system and give other processes a chance to breathe.

Waiting for the Clipboard

Tuesday, November 2nd, 2010

Today I was helping someone who was wanting to write a script to take screen-shots from one application and then paste those screen-shots into Microsoft Excel.

Initially things weren’t working reliably because the script didn’t factor in the time taken for the large bitmap of a screen-shot to exist in the clipboard after pressing the print screen button, before attempting to paste into Excel. E.g. consider:

Press Print Screen
SetFocus>Microsoft - Excel*
Press CTRL
Send>v
Release CTRL

The above is probably going to fail most of the time because a screen shot is a large bitmap and is going to take some time to arrive on the clipboard, but the script above performs a paste in Excel immediately after pressing print screen. The print screen key being depressed and the clipboard containing the bitmap are not the same thing.

While we could have just said “wait 5 seconds” and that would probably have been fine for evermore, it isn’t very sensitive and wouldn’t be ideal for a script that needs to run as fast as possible. Ideally we only want to wait until we know the bitmap is in the clipboard.

Text is usually smaller than a bitmap, but for large text items one way to make things bulletproof is to do something like this:

PutClipBoard>dummy

SetFocus>source_app_title
Press CTRL
Send>c
Release CTRL

Label>wait_for_data
Wait>0.2
GetClipBoard>clipdata
If>clipdata=dummy
  Goto>wait_for_data
Endif

By putting a known value onto the clipboard in the first place we can then have a little loop which keeps checking the clipboard until the returned value is not our known value. We then know our CTRL-V has worked and that we can safely paste to the target application.

But how can we do the same thing when the clipboard data is an image? The above won’t work because GetClipBoard won’t return anything for non-textual data.

Well, Windows has a function called IsClipboardFormatAvailable which will allow us to determine what kind of data is on the clipboard. So we could use this in a similar way to above to see if the clipboard contains a bitmap or not. Like this:

Let>CF_BITMAP=2

Let>haveBMP=0
PutClipBoard>dummy

Press Print Screen

While>haveBMP=0
  LibFunc>user32,IsClipboardFormatAvailable,haveBMP,CF_BITMAP
  Wait>0.2
EndWhile

We could then paste it somewhere:

SetFocus>Document - WordPad
Press CTRL
Send>v
Release CTRL

It’s always nice to wait only as long as we have to and it makes the script more reliable and portable.

ClipMagic 4.0 Released

Tuesday, October 19th, 2010

ClipMagic - Clipboard Extender Way back in 1998 we released a handy little Windows Clipboard extender and information manager called ClipMagic. It lives over at http://www.clipmagic.com/ where today after far too long a new version was released.

If you’re not already familiar with ClipMagic it is a Windows clipboard monitor/viewer/extender/manager which stores every item you copy to the windows clipboard and allows you to edit clips, organize them, manipulate and filter them, assign hot keys to them, and provides useful features to make it easier to paste clips into other windows. It is also an information manager, as you can create clips manually, assign them to categories and quickly retrieve/paste them using hot keys. Web clips are stored with the URL of the page they came from, allowing you quick access back to the source.

Basically it speeds up your work. The big problem with the native Windows clipboard is that it only stores one item at a time. You know that feeling when you have to copy lots of items from one screen to another and you have to go back and forth? Then a bit later you realise you need an item you copied earlier but it was obliterated by a recent copy? Well ClipMagic removes all that, because ClipMagic remembers every clip and gives you quick ways to paste into the active application.

For those familiar with previous versions of ClipMagic you may not notice any major difference in version 4.0 at first. But the big change is that version 4.0 has a completely new database format which is faster and more reliable. V 4.0 is also fully compatible with Vista and Windows 7 and supports the new Vista/Win7 clipboard monitoring method, so if you’re using Vista/Win7 you can say good bye to the annoying clipboard chain problems.

ClipMagic 4.0 comes in two flavours. As well as the full featured version, with a 30 day trial, there’s also a free Lite version which just keeps a copy of all clips giving you access to them but with no editing, filtering or custom hot key features.

More Info
Downloads

Macro Scheduler 12.1.0 Now Available

Monday, October 18th, 2010

Macro Scheduler 12.1.0 is now available with the following fixes since my last update announcement:

  • Fixed: IGNORESPACES ignoring CRLFs and SPACES when on their own.
  • Fixed: StringReplace crashes if empty string passed in find parameter
  • Fixed: Occassional “cannot write to comdef.ini” error in standalone editor.
  • Fixed: CTRL-V etc not working in Watch List search box
  • Fixed: Some text missing from GetTextInRect / GetWindowTextEx where text overlaps (New Text Capture libs)
  • Added: Full complex expression support to Repeat and While (when expr between curly braces)
  • Added: -KEEPLOGOPEN command line parameter: keeps log file open during script execution (faster for installations with large number of simultaneous running scripts)
  • Change: If insufficient privileges to open a script for exclusive write access (or if script already being edited) will now ask if you want to open it read only

Workflow Designer and the SDK have also been updated to the same MacroScript version.

Registered Downloads/Upgrades | Evaluation Downloads | New License Sales

Display an Animated GIF on a Dialog

Friday, October 15th, 2010

Forum regular JRL has come up with yet another great coding example, with a demonstration of how to jazz up your dialogs by displaying an animated image – a great way to represent progress of an activity.

Here it is.

In fact this example shows how any window can be embedded into a dialog by using the SetParent function. Take a look at JRL’s helpful comments to see how this works.