Close Server: KOPWWW05 | Not logged in


Welcome to Health Care POV | sign in | join
Stepwise Success

A Script Example

Published August 30, 2016 7:19 PM by Scott Warner

As promised, here is an example AutoIt script:

; NotepadMemo.au3 - example using AutoIt

#include <MsgBoxConstants.au3>
#include <Date.au3>
Local $sTo
Local $sSubject

If WinExists("Untitled - Notepad") Then
   $sTo = InputBox("Memo", "To:", "All Staff")
   $sSubject = InputBox("Memo", "Memo Subject:")
   WinActivate("Untitled - Notepad")
   Send("M E M O{ENTER}{ENTER}")
   Send("TO: " & $sTo & "{ENTER}{ENTER}")
   Send("FROM: The Big Boss{ENTER}{ENTER}")
   Send("DATE: " & _NowDate() & "{ENTER}{ENTER}")
   Send("SUBJECT: " & $sSubject & "{ENTER}{ENTER}")
   Send("____________________________________________________________________________{ENTER}{ENTER}")
   MsgBox($MB_OK, "Memo", "All set to write your memo, Boss. Continue?")
EndIf

Exit

What it does: if a blank Notepad document is open when you run this script, it prompts you to enter the To: and Subject: lines of a memo. It then creates the memo header, a trivial time saver. With modification this works with any word processor; all that’s needed is to change the WinExists(title) parameter. With a little more modification you can use this to create emails, too.

A few notes:

  • Your script can be documented with comments that are ignored by the interpreter. These are preceded by a semicolon. You can put these anywhere; anything after the semicolon is ignored. The #include lines are needed by the interpreter. These contain code that is needed for AutoIt’s internal functions.
  • Variables e.g. $sTo are “declared” before being used. These are all preceded by a dollar sign. Best practice naming convention is to also use an identifier of the type of data contained in the variable (s=string, i=integer, a=array). “Local” defines the scope of the variable, that is what parts of your program can access its contents. This lets you reuse variable types inside functions or declare Global variables that are used everywhere. That’s a very powerful feature.
  • Variables can be defined by constants ($sTo = “Everyone”) or by the product of a function. In this case, I’ve used the AutoIt InputBox() function, a good example of portability. This kind of internal command can be used everywhere, and you can even create your own.
  • Just like Excel formulae, the string parameter passed to the Send() function can be a constant, a variable, or a combination of the two. You can also include a function, joining the elements with an ampersand.

The actions of the script hinge on a conditional statement (sometimes called a branching statement). The idea is straightforward: If this, then that. There are many variations of conditional statements in computer programming. These can be nested (within an If-then you can have another If-then, and so on) and contain exceptions (If this, then that, else this). Along with loops, they are what drives and redirects your code. All computer languages have these basic elements.

The script fires by AutoIt’s built in Windows related functions. If you run it without Notepad being opened nothing happens, because If WinExists(“Untitled - Notepad”) is false. None of the code between If and Endif runs. It’s easy to add an Else clause that pops up a MsgBox reminding you to open Notepad first!

So now you have the elements to build a script to automate your LIS: a way to identify the window (WinExists), activate the window (WinActivate), receive any special input (InputBox), send keystrokes (Send, which can also include alt- and ctrl- combinations), and for the program to talk back to you (MsgBox). AutoIt can do much, much more, including mouse movements, mouse clicks, and reading and writing to files. It is a remarkably sophisticated programming tool. But all you need is the basics.

Suppose, for example, you want to automate printing a report. It’s not difficult to make a half-dozen clicks and enter date parameters, but AutoIt can do that faster and easier. You can use Windows task scheduler to run these automatically! All you need to know is what the title of the window is, where the cursor is, and what your next keystroke is. The Send() function includes constants for every keystroke.

The possibilities are numerous within the scope of simple, repetitive functions. This includes maintaining

and updating your item master. You can, for example, write a script to change all your barcode labels to a certain type. By hand this would take hours of work that is expensive payroll time. (Can we afford not to do this with our current shortages?) AutoIt can do this quickly and accurately. The best part of writing a script is portability: once a script is written it can be reused over and over with slight changes.

 

For those of you who want to try this, let me know how it works out. It will be worth your time.

NEXT: Is Lab Morale Plummeting?

posted by Scott Warner
tags:

0 comments

leave a comment



To prevent comment spam, please type the code you see below into the code field before submitting your comment. If you cannot read the numbers in the image, reload the page to generate a new one.

Captcha
Enter the security code below:
 

Search

About this Blog


    Scott Warner, MLT(ASCP)
    Occupation: Laboratory Manager
    Setting: Critical Access Hospital
  • About Blog and Author

Keep Me Updated

Recent Posts

Archives