October 28, 2008

Macro Scheduler Beta 11 Build 016 Available

Filed under: Announcements — Marcus Tettmar @ 3:17 pm

Build 016 has just been made available with the following fixes since the previous build:

– Prevent pressing Del key in search box causing macro delete warning
– Added “News Feed” option to help menus, brings up Macro Scheduler blog RSS feed
– RSS News Feed displayed on startup by default (can be switched off)
– Added link “Beginner’s Guide to Scripting Windows” in the Help menus
– SK_DELAY will now affect Press KEY * N actions
– Fixed: Search was unable to locate text in scripts that were imported but not yet modified
– ReadFile command now correctly reads Unicode files

Download from Registered Downloads page.

As you can see we’ve added a small RSS feed reader to this build. By default it will show when you first open Macro Scheduler. But you can switch this off easily. It is also available from the Help menus. The aim of this is to try and make more people aware of the many articles and resources that are available here as not everyone reads blogs, or subscribes to RSS feeds. Not only that but it will also allow us to keep people more up to date with maintenance releases etc.

October 27, 2008

Top Tips for Reliable Macros

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

Over the years I’ve helped many people improve their automation scripts. The most common two causes of scripts failing to work correctly and consistently are timing and focus issues. Here I’ve tried to summarise the main things you should do to make your scripts more reliable.

Try to avoid mouse clicks.

Mouse clicks require screen positions and while there are ways to specify window relative positions, or find the position of objects, if you can use the keyboard instead, it’s a lot less hassle. And most of the time you CAN use the keyboard instead of the mouse. You can TAB from object to object, field to field. You can press ALT to see the shortcut keys and select menu items and click buttons. You can toggle radio boxes with the SPACE bar. You can CTRL-TAB through tab pages. You can position the cursor, highlight text and copy to the clipboard, all with the keyboard. You can often select an item in a list box or combo box simply by typing the item you want to select.

For more info on keyboard shortcuts see:
http://www.mjtnet.com/blog/2006/01/16/keyboard-shortcuts/

Don’t automate mouse clicks or keystrokes just to start an application!

I’ve seen people write code to locate a desktop icon, then double click it, and even double click on a Windows Explorer icon, click through a series of folders and finally double click on an EXE. While this may work just fine, it’s rather long winded and seems a bit pointless when you can run an app with just one line of code. A desktop shortcut is just a shortcut to another file, usually an executable, sometimes with command line parameters. Right click on the shortcut and select Properties to see the target. Copy that and paste it into a Run command. E.g.:

Run>"C:\Program Files\Mozilla Firefox\firefox.exe"

One line of code is much easier to read, easier to maintain later and easier to debug. It’s also faster.

The other day I saw a Citrix app which the user would normally start by double clicking on the desktop icon which would present an Explorer style window appear. The user would then select one of the apps from the list in the Explorer Window. Rather than use image recognition to find the icons and send a bunch of mouse clicks we found that if you right click on one of the apps you could create a desktop shortcut. We did that and examined the shortcut to see what the actual command line was to run that app. We probably could have read the docs instead but we used the desktop shortcut to tell us and simply copied the target into Macro Scheduler, before deleting the desktop shortcut. We now had one line in Macro Scheduler to run the app directly.

How to automate a Save As or File Open dialog.

Need to manipulate a Save As or File Open dialog box? It seems many people think you HAVE to use the mouse to click through a series of folders to find the location of the file. WRONG! Ignore the folder browse area of the file dialog. All you have to do is type a full path into the file name box and hit Enter. Doesn’t matter what the current folder is that the dialog is showing you. Just type the path of the file you want:

WaitWindowOpen>Save As
Send>g:\some folder\some sub folder\some file.txt
Press Enter

That’s it! No mouse clicks necessary!

Make the script wait for events to complete.

Remember – scripts run faster than humans can type! Unless you build delays into the script it’ll just issue each step milliseconds after the last one. But apps are designed for humans who type more slowly and subliminally wait for events to complete – we don’t start typing into a window until we can see the window on the screen. We know that when we select File/Save As we need to wait for the Save As box to appear before we can enter the filename. So we need to make scripts do the same thing.

The most important command you should use in EVERY script is WaitWindowOpen. Whenever we issue a command which will make a new window open, use WaitWindowOpen to make the script wait for that window to appear before it continues:

//select File/Print
Press ALT
Send>fp
Release ALT

//wait for the print dialog
WaitWindowOpen>Print

//Press enter key
Press Enter

Without that WaitWindowOpen command the Press Enter will most likely be sent long before (in computer time) the print dialog has appeared. So the document won’t print.

Equally, use WaitWindowClosed when you do something that causes the window to disappear.

Sometimes it’s not a window you need to wait for, you might want to use WaitScreenImage to wait for any visual cue, or WaitScreenText, or WaitCursorChanged. Or you might need to wait for a file to appear, so you might create a little loop with IfFileExists in it …. it could be anything. Determine what events the script needs to be aware of and make it wait for them.

Be Specific.

The window functions can take an asterisk to look for a substring match for situations where the window title is not static, or not completely known. E.g.:

WaitWindowOpen>Internet Explorer*

But try to be as specific as you can. There are many hidden windows on your system so if your text matches one of those first it’ll stop at that one, not the one you want. Make the text more specific if possible, and/or use WF_TYPE to make Macro Scheduler look for only visible windows.

As an example, the following could return too quickly:

WaitWindowOpen>Microsoft Excel*

Why? Because “Microsoft Excel” is the window of the container application. But just after Excel starts you’ll see a window title something like “Microsoft Excel – Book1”. When the app starts, for a split second, faster perhaps than you can detect with the human eye, the window title might first be “Microsoft Excel” and THEN “Microsoft Excel – Book1”. So the above WaitWindowOpen line might return too quickly. You might not know what the first workbook will be, but you could do:

WaitWindowOpen>Microsoft Excel -*

Be as specific as you can for the final window title that you expect to see before you start automating it.

Slow scripts down! You can always speed them up later.

So you’ve followed the above advice and you’ve made the script wait for events to complete. You may still need some small delays. Let’s say you’re sending a bunch of keystrokes to a form, you’re tabbing through a window sending data to each field:

Press Tab
Send>Firstname
Press Tab
Send>Surname
Press Tab
Send>address
...

It’s not working? It works sometimes but not others? Here’s what is happening. The app is being overwhelmed by those keystrokes. It might do some “OnChange” style processing – as text is entered into a field it could be doing some processing internally. As mentioned before the script runs way faster than a human can type. The text is being sent to the app too fast. In real life there’d be a short delay between fields. So slow the script down and give the app a bit of a chance to catch up:

Press Tab
Wait>0.5
Send>Firstname
Press Tab
Wait>0.5
Send>Surname
Press Tab
Wait>0.5
Send>address
...

Half a second is probably all you need. It may not even need to be that much. But I always recommend that while you are developing a script and testing it you should err on the side of caution. Use plenty of waits. Get the script working. You can always reduce the waits later once you know it’s working. And if your script is going to be run unattended, say at night, then does it matter if it takes 5 seconds longer? Who’s watching it?

You can also use SK_DELAY to slow down the key send rate where you are sending characters together. SK_DELAY takes milliseconds:

Let>SK_DELAY=20
Send>Hello World

Sometimes you need to press tab a number of times to get to a field so you might do:

Press Tab * 6

But this sends the tabs in quick succession, and as I’ve said, the app may be requiring a bit of time between fields. So you might need to do the following instead:

Let>k=1
Repeat>k
  Press Tab
  Wait>0.2
  Let>k=k+1
Until>k=6

Make sure the correct window is focused!

When you press a key on the keyboard that keystroke will land in whatever the active window is. That’s the way your computer works. If Notepad is active and you type “Hello”, you’ll see “Hello” inside Notepad. If some other app is active … I don’t know what “Hello” would do in ficticious app number 2! Macro Scheduler controls your computer, so the same thing happens. That’s the way your computer works. So when you make Macro Scheduler send some text you’re going to want to make sure the correct window is focused first:

SetFocus>Notepad*
Send>Hello World

Build scripts in chunks.

When I develop a new macro I do it a few lines at a time. The first thing I might want the macro to do is open an application and wait for it to be ready. So I’ll do that bit manually and work out what paths, window titles and keystrokes I need to make that happen. I’ll write those lines of code. Then I’ll run the script and see if it gets me to where I want to go. Once those lines are doing the right thing I can work on the next phase. I’ll do a few more steps, add those to the script, then close the app down and run the script again.

Don’t try to build everything in one go, break the routine down into chunks and work build it up slowly.

Use the debugger!

The debugger is your friend. The debugger lets you step through the script line by line and watch the script working. You can see the value of variables as they are created and modified. So you can see just what each line is doing and find problems instantly. For a tutorial on using the debugger see:
http://www.mjtnet.com/blog/2006/05/17/use-the-debugger/

There’s also the variable explorer (Tools/Variable Explorer). Quite handy for finding variable related problems without having to run the script.

___
More resources:
http://www.mjtnet.com/blog/2006/01/17/how-to-start-writing-an-automation-script/
http://www.mjtnet.com/blog/2008/03/21/round-up-of-learning-resources/

October 24, 2008

October 23, 2008

Workflow Designer 1.2 Update

Filed under: Announcements — Marcus Tettmar @ 10:00 am

MacroScript Workflow Designer 1.2 is now available.

Workflow Automation - Click to View a Video Demo

Workflow Designer lets you create flowcharts and attach Macro Scheduler code to each step. You can then run your flowcharts.

This update fixes a few bugs including:

  • Fixed: Pressing stop button could sometimes cause a crash
  • Fixed: Non-visible blocks in large diagrams not being executed

    Evaluation Downloads | Registered Downloads

  • October 22, 2008

    SSH with Macro Scheduler

    Filed under: Automation, Scripting — Marcus Tettmar @ 1:20 pm

    As you know Macro Scheduler has Telnet, FTP and HTTP functions built in (and with v11 FTP/HTTP will support SSL). But what if you want to run some other secure protocol such as SSH?

    We’ve taken the view not to reinvent the wheel and add every possible secure communications protocol to Macro Scheduler, especially as there are some great components already available that you can use in your scripts. Rather than add bulk that won’t always get used, I’d prefer to leave the security stuff to the experts and use a plug-in component when needed, such as one of the Active-X components from WeOnlyDo Software.

    WeOnlyDo make Active-X components for all kinds of things, such as SSH and SFTP as well as the more general protocols Telnet, POP3, SMTP, amongst others. I recently downloaded their SSH component to help out a customer who needed a macro to access an SSH server, and was impressed with how easy it was to implement.

    You can download the SSH component here.

    Here’s an example I put together which logs into an SSH server, changes directory to /usr/bin and performs a directory listing, returning and displaying the results:

    VBSTART
    Function SSHExample(server,username,password)
      Dim ssh, a, resp
    
      Set ssh = CreateObject("WeOnlyDo.wodSSHCom.1")
    
      ssh.HostName = server
      ssh.Login = username
      ssh.Password = password
    
      ' set Blocking to true or false - blocking means the script is synchronous and waits for each method to complete
      ssh.Blocking = True
    
      ' Protocol: 0: Raw, 1: Telnet, 2: SSH1, 3: SSH2, 4: SSHAuto (Auto Negotiate)
      ssh.Protocol = 4
    
      ' remove ANSI codes from received data
      ssh.StripANSI = true
    
      'now connect
      ssh.Connect
    
      'wait for initial prompt
      ssh.WaitFor("regex:[\]\$] $")
    
      'issue a few commands, returning the output from the final one as the function result
      ssh.Execute "cd /usr/bin" & vbCRLF, "regex:[\]\$] $"
      SSHExample = ssh.Execute("ls -al" & vbCRLF, "regex:[\]\$] $")
    
      'finally disconnect
      ssh.Disconnect
    End Function
    VBEND
    
    Input>server,Server:
    Input>username,Username:
    Input>password,Password:
    
    // here we call the above VBS function to connect and run the command "ls -al"
    VBEval>SSHExample("%server%","%username%","%password%"),response
    
    //output the response
    MessageModal>response

    Notice the Execute statements above which execute a command and wait for the specified prompt to appear. The regex is simply waiting for any “]” or “$” found at the end of a line, which in my case signifies a prompt. Instead of using regex you can provide the exact prompt.

    The component is nicely documented in the help file, with useful examples, so you should find it pretty easy to get up and running.

    If you use any other components that work nicely with Macro Scheduler, let me know.

    October 21, 2008

    October 15, 2008

    Macro Scheduler 11 Beta Available

    Filed under: Announcements — Marcus Tettmar @ 9:59 am

    Having gone through a period of closed beta testing Macro Scheduler 11 Beta is now available to all registered customers. All registered users can log into their account and download the beta now.

    Just a summary of some of the main new features:

    • Unicode support in the UI as well as the script language.
    • A superb new script editor with better syntax highlighting, code folding and persistent bookmarks.
    • The script editor and macro properties windows have been combined into one – much easier to use – with everything under the one roof.
    • SSL/TLS support for the FTP functions as well as support for more flavours of FTP server.
    • SSL support for HTTPRequest.
    • Ability to easily embed any binary file into scripts and export them at runtime.
    • Ability to compile macros to console apps in order to write to STDOUT.

    You’ll find a fuller list and release notes here. Please read the release notes before installing.

    Please help test this version and report any issues to the Macro Scheduler Beta forum.

    Questions:

    When will the beta expire? The beta expires 31st December 2008.

    So, when will Macro Scheduler 11 be released? All being well beginning of January 2009, possibly sooner.

    And how much will it cost? Those with valid upgrade protection will get v11 at no additional cost. Otherwise you will need to purchase an upgrade. Current upgrade prices can be viewed on our upgrade page. There are no plans to change these prices at this stage. If you have v10 but don’t have upgrade protection you can purchase it by logging into your account.

    October 6, 2008

    Packaging files with your EXEs

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

    Every now and then people ask me how they can distribute other files along with their Macro Scheduler executables, such as DLLs or image files that your script requires.

    All software publishers face this problem and usually use an Install file creator, such as the free Inno Setup. You create a package of files and define how they are installed as well as what shortcuts to create etc. Most software you download is installed using software like this.

    For small packages you might get by with a simple zip file, or, better, a self extracting zip file. WinZip will create one of these for you. There’s also a tool that already comes with Windows called iexpress.exe. Click Start/Run and type iexpress.exe and hit Enter.

    This starts the IExpress Wizard which walks you through creating a self-extracting or self-installing package. It’s very simple to use. Just choose the files you want to be included in the package and select which one should be run on completion. You end up with an EXE you can give to your users/customers which when run will extract the files to a temporary folder and run your main script executable.

    Another way is to embed the files directly into your script and have your script extract them at runtime before it does anything else. Dick Lockey describes a way you can do that here. The next version of Macro Scheduler, version 11, makes this easier. It will include a tool to import any binary file into the script and a function called ExportData to create the file at runtime. If you use this method remember to write the files to somewhere you have access to. In a least privileged user environment that won’t necessarily be the EXE’s program folder. The temp folder might be safest. And if you do that, delete them afterwards.

    September 26, 2008

    Macro Scheduler 11 Progress Update

    Filed under: Announcements, General — Marcus Tettmar @ 12:46 pm

    Well we’ve been busy since my last post on code folding. The main changes include:

    * A completely overhauled script editor with even better code folding and bookmark support and improved syntax highlighting. The advanced editor and macro properties windows have been combined into one to make things much simpler and give easy access to things like the custom dialog designer and the debugger.

    Macro Scheduler 11 Editor

    * Macro Scheduler 11 has full Unicode support. Finally use any language characters in your scripts, detect Unicode text and output Unicode text.

    * Competely overhauled FTP functions with added TLS/SSL support and support for more flavours of FTP server.

    * Added SSL support to HTTPRequest

    * With v11 you can compile macros in “console app” mode and write to STDOUT

    * We’ve added the ability to embed any kind of file in a script, and export it at runtime.

    * And more.

    We’re just starting the initial stages of closed beta testing. Hopefully if all goes well we’ll be able to open the beta up in a month or so. In the mean time I’d be interested to hear from anyone with a need for TLS/SSL FTP support. If you have a TLS/SSL enabled FTP server and would like to do some testing please let me know.

    September 13, 2008

    Did you know you can get paid for selling our software?

    Filed under: Announcements, General — Marcus Tettmar @ 8:00 pm

    You too can sell Macro Scheduler through our Affiliate program.

    We are offering commissions of 20% on all sales made through your website. Through our Affiliate partner Shareasale.com you can join up immediately and start selling today. There are no set up fees and signing up is simple.

    Three easy steps to revenue:

    1. Sign up with www.shareasale.com
    2. Follow their instructions to place the Macro Scheduler link on your site
    3. Using Cookies and your Shareasale.com ID anyone who buys Macro Scheduler having come from your site earns you 20% commission

    How much could you earn?

    Single user licenses start at $115 and our 25 Pack Enterprise license is $4600, so you can earn from between $23 and $1150 per sale, and that’s not including popular options such as upgrade protection.

    For more info see:
    http://www.shareasale.com/shareasale.cfm?merchantID=10663