July 27, 2009

Think like a user, not a programmer

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

I just helped out a customer who was getting increasingly frustrated trying to get a macro to select a menu. The menu shortcut key was “g” and all he was trying to do was send Alt-g to the window. But whatever he tried he couldn’t get it to work.

Being an experienced programmer who had built Windows interfaces he had assumed that ALT-g (Alt together with “g”) would work:

Press ALT
Send>g
Release ALT

But nothing happened. He added waits in all sorts of various places but no cigar.

Eventually he called me up for a BeamYourScreen session and I took a look. I went back to basics, and tried the app out manually, making no assumptions. I entered ALT-G (g together with the ALT key) and found nothing happened. I then pressed the ALT key and released it. The app focused the first “File” submenu. I then hit “g” on its own and the required menu opened. Bingo.

Turns out the app doesn’t work the way either of us expected. The shortcuts should work when sent with the ALT key held down. But that wasn’t the case. One had to press ALT, release it, then send the shortcut character on its own. So the working code was:

Press ALT
Release ALT
Send>g

The mistake here was making assumptions based on our expectations and prior knowledge. A less experienced user may actually have got it working sooner by not taking anything for granted.

The trick to automating an app is to go back to basics, break it down and actually watch what you do. If my customer had actually tried it manually and taken a closer note of what exact keystrokes he had pushed, he would have made progress faster, instead of assuming that the app worked the way any UI guru would expect, and blaming the macro when it didn’t.

Think like a user not a programmer. To automate something first try it manually, write down or remember what sequence worked then replicate that in the macro – just as I preach in the Beginner’s Guide and Getting Started Guide.

No matter how technical you might be, this getting started guide is helpful.

July 20, 2009

Programming Results without Programming Experience

Filed under: Podcasts — Marcus Tettmar @ 9:47 am

In our newest customer podcast Joe Kitt of John R Lyman Company talks about their Order Auto-Acknowledgement system he built using Macro Scheduler which automatically acknowledges all orders coming into their ERP system. Although Joe has been working in IT for 20 years he has so far avoided doing any programming and says that Macro Scheduler allowed him to achieve programming results quickly without any programming experience. At John R Lyman Macro Scheduler is now helping to cut down on manual processes, increase efficiency and awareness and improve the quality of their data.

Download Listen

Listen to more Customer Podcasts.

July 2, 2009

Selecting from a Drop Down List

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

A project I’m currently working on involves populating data into a rather poorly designed user interface.  A particular challenge were the drop down lists and list boxes due to the fact that you can’t “drill down” by sending the text of the item you want selected.

The solution we settled upon uses the text capture function GetTextAtPoint in a loop which arrows down the entire list, with GetTextAtPoint capturing the text in the selection box to see if it’s the value required.  If it is we stop, else we continue to press down and loop.  We stop if the item selected is the same as the previous item, signifying that we’ve reached the end (obviously this assumes the list doesn’t have duplicates appearing together).

Here’s the subroutine:

SRT>dropDownSelect
/*****
Usage: GoSub>dropDownSelect,X,Y,text_to_select

Where X and Y are coordinates in the edit box (where the item appears once selected)
 and text_to_select is the text you want selected  

Important: the drop down needs to have the focus
*****/
  If>dropDownSelect_Var_3<>
    GetTextReset
    Press Home
    Wait>0.1
    Let>prev_comboText=Z@$%#XXX
    Let>dropDownFound=FALSE
    Label>select_drop
    GetTextAtPoint>dropDownSelect_Var_1,dropDownSelect_Var_2,comboText,c
    Pos>dropDownSelect_Var_3,comboText,1,p
    If>p<>1
      If>prev_comboText<>comboText
        Press Down
        Wait>0.2
        Let>prev_comboText=comboText
        Goto>select_drop
      Endif
    Else
      Let>dropDownFound=TRUE
    Endif
  Endif
END>dropDownSelect

So, for example, you could call it something like:

Press Tab
GoSub>dropDownSelect,240,355,Apples

Note that the drop down needs to be focused. Usually you’d be “tabbing” through fields on the form, so once you’ve used “Press Tab” to get focus onto the control you can call dropDownSelect.

This version requires that you pass the X,Y screen position of the text box area of the drop down. In development at the moment we have a new function which returns the handle of the currently focused object, and this can then be used in GetWindowPos to get the X,Y position. So in future you will be able to determine the X,Y position dynamically.

Hopefully you won’t need this function as you can usually “drill down” on a list box or drop down list by sending the text of the item you want as mentioned here. But for those badly designed controls that won’t allow that this function can be a life saver.

June 29, 2009

Macro Scheduler 11.1.12 Update

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

Macro Scheduler 11.1.12 is now available with the following changes:

  • Fixed: FTPGetDirList issue with format of directory list and wildcard matching with some flavours of FTP server
  • Fixed: Issue with ExportData adding extra erroneous character to end of exported text files
  • Fixed: FindImagePos using SCREEN for haystack fails under Remote Desktop/Terminal Server session

Registered Downloads/UpgradesEvaluation DownloadsNew License Sales

June 26, 2009

Weddings and Updates

Filed under: Announcements, General — Marcus Tettmar @ 11:03 am

Apologies for the quietness on my blog lately.  This month has been a busy one for me personally as on 13th June I – finally – married my partner of 6 years (and the mother of my children), Angela, and went away for a short, but very relaxing, honeymoon last weekend.

We at MJT have also been busy working on some client projects, so it has been a bit of a manic month all round and I didn’t manage to get a newsletter out for June.   But I plan to put one together for next week.  We should also have a Macro Scheduler maintenance release out soon, and have also started on some new video tutorials.  So watch this space!

June 8, 2009

Macro Scheduler 11.1.11 Update

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

Macro Scheduler 11.1.11 is now available with the following changes:

  • Fixed: Some issues with running macros via msNet (Remote Controller) component (Enterprise)
  • Fixed: Image Capture Tool incorrectly focusing main window after capture when run in standalone editor mode
  • Improvement: StringReplace speed improvements

Registered Downloads/Upgrades | Evaluation Downloads | New License Sales

June 4, 2009

Calling Macro Scheduler Scripts from VB/VBA

Filed under: General, Scripting — Marcus Tettmar @ 4:10 pm

I’m often asked how you can run Macro Scheduler macros from other programming languages, particularly VB.  

Macro Scheduler scripts can be run from the command line.  See the help file topic “Command Line Options”.  E.g.:

msched.exe “c:\someplace\mymacro.scp”

VB/VBA lets you execute external commands/applications via the Shell function:

Shell “””c:\program files\macro scheduler 11\msched.exe”” “”c:\scripts\example.scp”””, vbNormalFocus

The only problem with the Shell function is that it does not wait until what it is calling has finished running before continuing.  So it fires off the macro and the program continues.  In most cases you’d want to wait for the script to finish before you continue.  To do this you can use the following ShellAndWait function:

    Private Declare Sub Sleep Lib "kernel32" ( _
        ByVal dwMilliseconds As Long)
    Private Declare Function GetExitCodeProcess Lib "kernel32" ( _
        ByVal hProcess As Long, ByVal lpExitCode As Long) As Long
    Private Declare Function timeGetTime Lib "winmm.dll" () As Long
    Private Declare Function OpenProcess Lib "kernel32" ( _
        ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Private Const STILL_ACTIVE = &H103
    Private Const PROCESS_QUERY_INFORMATION = &H400
    Private Declare Function CloseHandle Lib "kernel32" ( _
        ByVal hObject As Long) As Long

    Public Function ShellAndWait( _
     ByVal sShell As String, _
            Optional ByVal eWindowStyle As Integer = vbNormalFocus, _
            Optional ByRef sError As String = "", _
            Optional ByVal lTimeOut As Long = 2000000000 _
        ) As Boolean
        Dim hProcess As Long
        Dim lR As Long
        Dim lTimeStart As Long
        Dim bSuccess As Boolean

        On Error GoTo ShellAndWaitError

        ' This is v2 which is somewhat more reliable: 
        hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(sShell, eWindowStyle))
        If (hProcess = 0) Then
            sError = "This program could not determine whether the process started." & _
                 "Please watch the program and check it completes."
            ' Only fail if there is an error - this can happen 
            ' when the program completes too quickly. 
        Else
            bSuccess = True
            lTimeStart = timeGetTime()
            Do
                ' Get the status of the process 
                GetExitCodeProcess(hProcess, lR)
                ' Sleep during wait to ensure the other process gets 
                ' processor slice: 
DoEvents:       Sleep(100)
                If (timeGetTime() - lTimeStart > lTimeOut) Then
                    ' Too long! 
                    sError = "The process has timed out."
                    lR = 0
                    bSuccess = False
                End If
            Loop While lR = STILL_ACTIVE
        End If
        ShellAndWait = bSuccess

        Exit Function

ShellAndWaitError:
        sError = Err.Description
        Exit Function
    End Function

So your code becomes:

ShellAndWait “””c:\program files\macro scheduler 11\msched.exe”” “”c:\scripts\example.scp”””, vbNormalFocus

If you have Macro Scheduler Pro you can compile the script to an EXE and then just execute the exe, making the command line simpler:

ShellAndWait “c:\someplace\mymacro.exe”, vbNormalFocus

The above code is based on the code found here.

June 3, 2009

T-Shirt Winner for May

Filed under: General — Marcus Tettmar @ 11:21 am

This month a fancy MJT Net logo T-Shirt goes to Rain for receiving 10 forum reputation points in May.  Thanks, Rain, for your valuable contributions on the forums and for continuing to help others out.  

Don’t forget that each month I send T-Shirts to the people receiving the most reputation points in the previous month.  So if you’re not already active in the forums, get stuck in – you could win a T-Shirt.

Make it Easier with a Few Basic Windows Skills

Filed under: Automation, General — Marcus Tettmar @ 10:17 am

Some pre-sales questions we get seem to suggest that the user lacks basic Windows skills.  What surprises me is that these questions are often from people working in company IT departments.  Their ability to comprehend how to automate something appears to be diminished by their inability to use a PC effectively.  Perhaps I’m being unfair – I guess it’s easy to forget that there’s another way to do something.

For example.  We might get asked:

“How do I make my macro click on a desktop shortcut if I don’t know where that desktop shortcut is going to be, and I want the macro to work on any PC where the desktop shortcut could be in different places?”.  

Think about it for a second. The answer is that you do NOT click on the desktop shortcut.  Why would you?  The clue is in the name – a shortcut is .. a shortcut to something.  Why would you record or write a macro that clicks on an icon when the macro simply needs to run whatever the shortcut runs?  Right click on the shortcut to show its properties and look at what the shortcut executes.  Copy that into your script and have the Run or ExecuteFile command run it.

As I said in Top Tips for Reliable Macros: Don’t automate mouse clicks or keystrokes just to start an application!

Now, even if you did want to select a desktop shortcut, there’s still another way to do it without needing to know or care where it is.  Just type it.  If you focus the desktop and type the name of a desktop shortcut on the keyboard it will get selected.  This is what I call “drill down” and it works on most lists.  So your macro could just send the text of the item.

When we get asked questions like this I’m always a little surprised.  I would have expected someone in an IT department to know what a desktop shortcut is and also to know that you can control Windows via the keyboard.

Of course, if you really, really want to create a macro that double clicks on a shortcut using the mouse and want it to find its position you can do that with image recognition.  In some applications, like the one I wrote about yesterday, that is the only way to go.  But it’s overkill if you just want to start an application, or run a file.

See also: Keyboard Shortcuts; Top Tips for Reliable Macros