Download presentation
Presentation is loading. Please wait.
1
AutoIt and Millennium: “Smart” Scripting
Harvey E. Hahn Manager – Technical Services Department Arlington Heights Memorial Library Arlington Heights, Illinois © b y H a r v e y E . H a h n © b y H a r v e y E . H a h n
2
Purpose This presentation is not about writing scripts in general!
Although AutoIt can be used for telnet scripting, this presentation will deal only with Millennium © b y H a r v e y E . H a h n
3
Purpose This presentation is about using your existing programming knowledge and skills plus new tools to write scripts that help accomplish Millennium tasks You will not learn detailed knowledge about AutoIt, but you will learn helpful patterns, tips, and techniques to use in your scripts for Millennium © b y H a r v e y E . H a h n
4
What is a script? One or more groups of instructions
that perform a sequence of window actions, often entering, modifying, and/or deleting data, imitating what a person would perform © b y H a r v e y E . H a h n
5
What is “dumb” scripting?
Sends text, keystrokes, and mouse clicks to one or more windows “blindly” Does not (and cannot) “react” to what is happening on the screen Millennium keystroke “macros” are simple examples of this © b y H a r v e y E . H a h n
6
What is “smart” scripting?
“Aware” of which window is currently displayed Can “react” appropriately to screen behavior Sends text, keystrokes, and mouse clicks to one or more windows “intelligently” Can “read” textual data from the screen and act upon it in some way © b y H a r v e y E . H a h n
7
Why use scripts? Result : Increased efficiency Increased productivity
Computer can do what it’s good at Speed Repetition People can do what they’re good at Judgment / Decision making Result : Increased efficiency Increased productivity © b y H a r v e y E . H a h n
8
Product comparison Cost GUI capabilities
AutoIt, VBScript, and Expect are free OCLC Macro Language is freely available to OCLC customers only Macro Express costs $40 per computer GUI capabilities AutoIt and Macro Express do windows VBScript, Expect , and OML do not © b y H a r v e y E . H a h n
9
Why choose AutoIt? Programming language with similarities to Visual Basic Scripts can work with Windows, not just telnet FREE! © b y H a r v e y E . H a h n
10
Where to get it? AutoIt v3 Home Page
SciTE (Scintilla-based Text Editor) © b y H a r v e y E . H a h n
11
Installation tip Although Edit the script is the “recommended” SciTE doubleclick option, do NOT choose it! Instead, let the default option remain as Run the script © b y H a r v e y E . H a h n
12
SciTE Customizable full-screen text editor specially adapted for AutoIt Author pronounces name as “shkyt” Syntax highlighting (color-coded) Full help for AutoIt commands Integrated window information utility Scripts can be compiled to .exe files © b y H a r v e y E . H a h n
13
SciTE—Syntax highlighting
© b y H a r v e y E . H a h n
14
SciTE—AutoIt help © b y H a r v e y E . H a h n
15
SciTE—Window info utility
1 2 © b y H a r v e y E . H a h n
16
SciTE—Window info utility
© b y H a r v e y E . H a h n
17
SciTE—Compiled files 2 1 © b y H a r v e y E . H a h n
18
Why both AutoIt and SciTE?
Use SciTE to write AutoIt scripts Use AutoIt to follow script instructions SCRIPT ( SciTE ) AutoIt Actions © b y H a r v e y E . H a h n
19
Testing (or running) scripts
1 2 or F5 key © b y H a r v e y E . H a h n
20
Other helpful tools FRHED (FRee Hex EDitor)
© b y H a r v e y E . H a h n
21
FRHED © b y H a r v e y E . H a h n
22
Some programming basics
Function Performs an action Returns a value: number, text, success (true/false) Syntax conversions How common commands look in AutoIt © b y H a r v e y E . H a h n
23
Some programming basics Syntax conversions
Visual Basic / OML 'remark Dim abc As ... abc = ... Dim WinSize(2)... AutoIt ;remark Dim $abc $abc = ... Dim $WinSize[2] © b y H a r v e y E . H a h n
24
Some programming basics Syntax conversions
Visual Basic / OML Function Fname(…) Fname = value End Function Sub name(…) End Sub AutoIt Func Fname(…) Return $value EndFunc Func name(…) [no return value] © b y H a r v e y E . H a h n
25
Some programming basics Syntax conversions
Visual Basic / OML AppActivate SendKeys [OML: Receive] [no equivalent] AutoIt WinActivate * Send WinWaitActive * Sleep * similar function, not identical © b y H a r v e y E . H a h n
26
Some programming basics Syntax conversions
Visual Basic / OML Len Left[$] Mid[$] Right[$] AutoIt StringLen StringLeft StringMid StringRight © b y H a r v e y E . H a h n
27
Some programming basics Syntax conversions
Visual Basic / OML LTrim[$] RTrim[$] Trim[$] UCase[$] LCase[$] AutoIt [no equivalent] StringUpper StringLower © b y H a r v e y E . H a h n
28
Some programming basics Syntax conversions
Visual Basic / OML Clipboard.GetText Clipboard.PutText AutoIt ClipGet ClipPut © b y H a r v e y E . H a h n
29
What’s next? Typing keystrokes Window coordinates
Clicking buttons / tabs / icons “Where am I?” Getting data from windows © b y H a r v e y E . H a h n
30
Typing keystrokes Syntax Examples
Send( “<one or more keystrokes>” ) Send( $variablename ) Examples Send( “ ” ) ;enter item barcode Send( $Barcode ) Send( “!y” ) ;Alt-y = choose the “Yes” button Send( "+{TAB 4}” ) ;presses Shift-Tab 4 times Send( “^c” ) ;Ctrl-c = copy data to clipboard Any scripting language can do this in Millennium © b y H a r v e y E . H a h n
31
Typing keystrokes Known issue with Microsoft Windows:
A script can send keystrokes faster than Windows can process them Programmers need to insert delays after Send commands to permit Windows to catch up The delay value should be at least 2/10ths of a second, possibly more This isn’t a problem with a human typist, but a computer “typist” is much faster © b y H a r v e y E . H a h n
32
Typing keystrokes Syntax Examples Sleep( <1000ths of a second> )
Sleep( 200 ) ;pause 2/10ths of a second Sleep( 5000 ) ;wait 5 seconds © b y H a r v e y E . H a h n
33
Typing keystrokes For the Send command to work successfully, the Sleep command needs to be paired with it: Send( “John{ENTER}” ) Sleep( 200 ) Send( “Smith{ENTER}” ) © b y H a r v e y E . H a h n
34
Typing keystrokes More efficient approach: Func Type( $Text )
Send( $Text ) Sleep(400) ;add pause after sending text EndFunc . . . Type( “John{ENTER}” ) Type( “Smith{ENTER}” ) © b y H a r v e y E . H a h n
35
Typing keystrokes Millennium scripting tip:
Always first try using a keyboard shortcut (before trying mouse clicks) because it’s the easiest and most reliable technique © b y H a r v e y E . H a h n
36
Typing keystrokes Millennium keyboard equivalents:
# – function keys # – general shortcut keys # – window controls and associated shortcut keys © b y H a r v e y E . H a h n
37
Typing keystrokes Millennium keyboard equivalents
© b y H a r v e y E . H a h n
38
Typing keystrokes Millennium keyboard equivalents
© b y H a r v e y E . H a h n
39
Typing keystrokes Millennium keyboard equivalents
© b y H a r v e y E . H a h n
40
Typing keystrokes Millennium keyboard equivalents
© b y H a r v e y E . H a h n
41
Typing keystrokes Millennium keyboard equivalents
© b y H a r v e y E . H a h n
42
Typing keystrokes Millennium keyboard equivalents
© b y H a r v e y E . H a h n
43
Discussion demo © b y H a r v e y E . H a h n
44
Discussion demo © b y H a r v e y E . H a h n
45
Discussion demo © b y H a r v e y E . H a h n
46
Discussion demo © b y H a r v e y E . H a h n
47
Discussion demo © b y H a r v e y E . H a h n
48
Discussion demo © b y H a r v e y E . H a h n
49
Discussion demo © b y H a r v e y E . H a h n
50
Discussion demo © b y H a r v e y E . H a h n
51
Discussion demo © b y H a r v e y E . H a h n
52
Discussion demo © b y H a r v e y E . H a h n
53
Discussion demo © b y H a r v e y E . H a h n
54
Window coordinates The screen is the entire desktop
A window is placed somewhere on the screen A Millennium window usually covers the entire screen © b y H a r v e y E . H a h n
55
Window coordinates Coordinates are zero-based from the upper left corner of a window or screen Coordinates inside of a window stay the same, regardless of where a window is located on the screen © b y H a r v e y E . H a h n
56
Window coordinates 98 79 98 79 © b y H a r v e y E . H a h n
57
Window coordinates Millennium scripting tip: Syntax NOTE:
A window must be maximized for consistent coordinates Syntax WinSetState( $WinName, ) NOTE: This command will even maximize windows which have no maximize button! © b y H a r v e y E . H a h n
58
Window coordinates © b y H a r v e y E . H a h n
59
Window coordinates © b y H a r v e y E . H a h n
60
Window coordinates © b y H a r v e y E . H a h n
61
Window coordinates Millennium scripting tip:
The screen resolution affects coordinates! Always indicate your screen resolution in the script preliminaries—this helps others when using or adapting your script © b y H a r v e y E . H a h n
62
Window coordinates © b y H a r v e y E . H a h n
63
Window coordinates © b y H a r v e y E . H a h n
64
Clicking buttons/tabs/icons
Syntax MouseClick( $button, $x, $y, $clicks, $speed ) Example MouseClick( "left", 400, 300, 1, 0 ) © b y H a r v e y E . H a h n
65
Clicking buttons/tabs/icons
More efficient approach: Func ClickAt( $x, $y ) MouseClick( "left", $x, $y, 1, 0 ) Sleep(400) ;add pause after clicking mouse EndFunc . . . ClickAt( 400, 300 ) © b y H a r v e y E . H a h n
66
Clicking buttons/tabs/icons
Clicking depends on the desired coordinates of the mouse pointer on a screen or window Coordinates may be relative to: a given window the full screen © b y H a r v e y E . H a h n
67
Clicking buttons/tabs/icons
Window-based coordinates © b y H a r v e y E . H a h n
68
Clicking buttons/tabs/icons
Screen-based coordinates © b y H a r v e y E . H a h n
69
Clicking buttons/tabs/icons
By default, mouse coordinates are screen-based, not window-based Yet, to keep coordinates inside of a window stable, they should always be relative to that window (not to the screen) © b y H a r v e y E . H a h n
70
Clicking buttons/tabs/icons
To resolve this seeming contradiction, offsets are needed from the screen edges to a window’s upper left corner (“origin”) Syntax to change this (not recommended) AutoItSetOption( “MouseCoordMode”, $mode ) 0 = window-based = screen-based (default) © b y H a r v e y E . H a h n
71
Clicking buttons/tabs/icons
Y offset X offset © b y H a r v e y E . H a h n
72
Clicking buttons/tabs/icons
Match coordinate references to the type of justification being used Add offsets to left edge for left-justified text, tabs, icons, etc. Subtract offsets from right edge for right-justified text, tabs, icons, etc. © b y H a r v e y E . H a h n
73
Clicking buttons/tabs/icons
© b y H a r v e y E . H a h n
74
Clicking buttons/tabs/icons
Example 1 (useful for full-size windows) ;dimensions of window ( 0=width, 1=height ) Dim $WinSize[2] . . . ;maximize the Millennium window... WinSetState( "Millennium", ) ;...and get its dimensions $WinSize = WinGetClientSize("Millennium") ;click "Put FTS" button (referenced from right edge) ClickAt( $WinSize[0]-30, 70 ) © b y H a r v e y E . H a h n
75
Clicking buttons/tabs/icons
© b y H a r v e y E . H a h n
76
Clicking buttons/tabs/icons
1 2 © b y H a r v e y E . H a h n
77
Clicking buttons/tabs/icons
© b y H a r v e y E . H a h n
78
Clicking buttons/tabs/icons
1 2 3 © b y H a r v e y E . H a h n
79
Clicking buttons/tabs/icons
© b y H a r v e y E . H a h n
80
Clicking buttons/tabs/icons
Example 2 (useful for smaller subwindows) ;aspects of window ( 0=X-pos, 1=Y-pos, 2=width, 3=height ) Dim $WinSize[4] . . . ;get full size of window $WinSize = WinGetPos("Millennium control bar") $WinX = $WinSize[0] $WinY = $WinSize[1] $WinWidth = $WinSize[2] $WinHeight = $WinSize[3] © b y H a r v e y E . H a h n
81
“Where am I?” Getting the title of the active window Why?
Identify various windows (login, processing, get info from user, etc.) Syntax $title = WinGetTitle( "" ) $fulltitle = WinGetTitle( $partialtitle ) © b y H a r v e y E . H a h n
82
“Where am I?” Waiting for a window Why?
Script must wait until a given window is “ready for action” Script might need to check for possible appearance of an “optional” window This is one of the most important aspects of GUI scripting! © b y H a r v e y E . H a h n
83
“Where am I?” Waiting for a window Syntax (waiting to become active)
WinWaitActive( $title ) $success = WinWaitActive( $title, "", $maxsecs ) If WinWaitActive( $title, “”, $maxsecs ) > 0 Then… Opposite syntax (waiting to become not active) WinWaitNotActive( $title ) etc. © b y H a r v e y E . H a h n
84
“Where am I?” Getting pixel colors of text, background, or images (“worst case” scenario) Syntax (default = screen coordinates) $hexcolor = Hex( PixelGetColor( $x, $y ), 6 ) 0 = black FFFFFF = white RRGGBB © b y H a r v e y E . H a h n
85
“Where am I?” Distinguish windows with same titles “C” “D”
© b y H a r v e y E . H a h n
86
“Where am I?” Using patterns of pixels to identify characters on the screen is why it is so important to maximize windows and thus stabilize coordinates Coordinates being “off” by 1 or 2 pixels can make all the difference in the world! © b y H a r v e y E . H a h n
87
“Where am I?” Using a 4-pixel pattern, the difference between “o” and “c” might be a single pixel (the opening of the “c”) © b y H a r v e y E . H a h n
88
“Where am I?” 1 2 © b y H a r v e y E . H a h n
89
“Where am I?” 3 4 © b y H a r v e y E . H a h n
90
“Where am I?” Pixel 1 4 2 3 © b y H a r v e y E . H a h n
91
“Where am I?” Pixel 1 4 2 3 © b y H a r v e y E . H a h n
92
“Where am I?” Example $BCol = "FFFFFF" ;background color (white)
; check selected pixels for the character "c" (checkin record type) $Pxl1 = Hex( PixelGetColor( 11, 314 ), 6 ) $Pxl2 = Hex( PixelGetColor( 13, 317 ), 6 ) $Pxl3 = Hex( PixelGetColor( 11, 320 ), 6 ) $Pxl4 = Hex( PixelGetColor( 9, 317 ), 6 ) If $Pxl1<>$BCol And $Pxl2=$BCol And $Pxl3<>$BCol And $Pxl4<>$BCol Then $IsCheckinRec = $TRUE Else $IsCheckinRec = $FALSE ; this is NOT a checkin record EndIf © b y H a r v e y E . H a h n
93
Getting data from windows
“Reading” data off the screen is often the most difficult and challenging task when writing scripts to automate Millennium © b y H a r v e y E . H a h n
94
Getting data from windows
Selecting (highlighting) text Syntax ; use standard “select all” command (Ctrl-a): Send( “^a” ) Sleep(400) ; ; or use self-written function: Type( $Ctl & “a” ) © b y H a r v e y E . H a h n
95
Getting data from windows
Using the clipboard Syntax $text = ClipGet() ;get data from clipboard ClipPut( $text ) ;put data onto clipboard Note: It is standard practice to clear the clipboard before copying any data to it © b y H a r v e y E . H a h n
96
Getting data from windows
Example Func GetHighlightedData() ClipPut( "“ ) ; always clear the clipboard first! Type( $Ctl & “c“ ) ; copy highlighted data to the clipboard Type( $Ctl & “c“ ) ; duplicate needed for reliability (why??) $HighlightedData = ClipGet() ; put data into a variable Return $HighlightedData EndFunc . . . Type( $Ctl & “a” ) ; select (highlight) all editable text $text = GetHighlightedData() © b y H a r v e y E . H a h n
97
Getting data from windows
Tables Algorithm Choose a row, using Home, End, Up, or Down or Rapidly type a row number or Click a row in the table Copy the auto-highlighted data into a string Parse the string, looking for specific data © b y H a r v e y E . H a h n
98
Getting data from windows
© b y H a r v e y E . H a h n
99
Getting data from windows
© b y H a r v e y E . H a h n
100
Getting data from windows
© b y H a r v e y E . H a h n
101
Getting data from windows
© b y H a r v e y E . H a h n
102
Getting data from windows
© b y H a r v e y E . H a h n
103
Getting data from windows
© b y H a r v e y E . H a h n
104
Getting data from windows
check for this text © b y H a r v e y E . H a h n
105
Getting data from windows
© b y H a r v e y E . H a h n
106
Getting data from windows
© b y H a r v e y E . H a h n
107
Getting data from windows
Dropdown lists Elements in these lists cannot be “read” by AutoIt Identifiable elements There is known data that can be used to distinguish and choose elements in the list Unidentifiable elements No data in the elements in the list can be used to distinguish or choose any of the elements © b y H a r v e y E . H a h n
108
Getting data from windows
Dropdown lists Identifiable elements “If the list item has a bold letter preceding it, you can select the list item by pressing the letter.” (Manual # ) Algorithm Choose the list (usually an Alt-key combination) Send( “c” ) or Send( “i” ) or Send( $choice ) © b y H a r v e y E . H a h n
109
Getting data from windows
© b y H a r v e y E . H a h n
110
Getting data from windows
No letters, yet works! Note: first element is NOT default! © b y H a r v e y E . H a h n
111
Getting data from windows
Dropdown lists Unidentifiable elements Its ordinal position in the list is the only way to refer to an element Algorithm Choose the list (usually an Alt-key combination) “Hard code” the list choices into the script Based on the desired choice, use Home, End, and the Up and Down arrows to move the highlight to the corresponding list element Send( “{ENTER}” ) to choose that element © b y H a r v e y E . H a h n
112
Getting data from windows
© b y H a r v e y E . H a h n
113
Getting data from windows
END key moved to last element © b y H a r v e y E . H a h n
114
Getting data from windows
Fixed-field tables and variable fields (screen editor variations) Algorithm Click anywhere within the table or record Select all of the data (Ctrl-a) Copy the data into a string Parse the string, looking for specific data © b y H a r v e y E . H a h n
115
Getting item data © b y H a r v e y E . H a h n
116
Getting item data © b y H a r v e y E . H a h n
117
Getting item data © b y H a r v e y E . H a h n
118
Getting item data hex 20 = space © b y H a r v e y E . H a h n
119
Getting item data © b y H a r v e y E . H a h n
120
Getting item data © b y H a r v e y E . H a h n
121
hex 0d 0a = CRLF (end of line)
Getting item data hex 09 = TAB (not spaces) hex 0d 0a = CRLF (end of line) © b y H a r v e y E . H a h n
122
Getting bib data © b y H a r v e y E . H a h n
123
Getting bib data © b y H a r v e y E . H a h n
124
Getting bib data © b y H a r v e y E . H a h n
125
Getting bib data © b y H a r v e y E . H a h n
126
Getting bib data hex 20 = space © b y H a r v e y E . H a h n
127
Getting bib data © b y H a r v e y E . H a h n
128
Getting bib data © b y H a r v e y E . H a h n
129
Getting bib data hex 09 = TAB (not spaces)
© b y H a r v e y E . H a h n
130
Getting bib data hex 0d 0a = CRLF (end of line)
hex 7c = subfield_delimiter (pipe) hex 09 = TAB (not spaces) © b y H a r v e y E . H a h n
131
REVIEW using Data Exchange
OPTIONAL: check title for correct window © b y H a r v e y E . H a h n
132
REVIEW using Data Exchange
OPTIONAL: check pixels for correct screen © b y H a r v e y E . H a h n
133
REVIEW using Data Exchange
send keystroke © b y H a r v e y E . H a h n
134
REVIEW using Data Exchange
send keystroke (DOWN key) © b y H a r v e y E . H a h n
135
REVIEW using Data Exchange
send keystroke (END key) © b y H a r v e y E . H a h n
136
REVIEW using Data Exchange
send keystroke (ENTER key) © b y H a r v e y E . H a h n
137
REVIEW using Data Exchange
click mouse © b y H a r v e y E . H a h n
138
REVIEW using Data Exchange
send keystroke (TAB key) © b y H a r v e y E . H a h n
139
REVIEW using Data Exchange
send keystroke (SHIFT-HOME key) © b y H a r v e y E . H a h n
140
REVIEW using Data Exchange
send keystrokes (IP address) © b y H a r v e y E . H a h n
141
REVIEW using Data Exchange
send keystroke © b y H a r v e y E . H a h n
142
REVIEW using Data Exchange
send keystrokes: Alt-u user_name Alt-p password © b y H a r v e y E . H a h n
143
REVIEW using Data Exchange
send keystroke © b y H a r v e y E . H a h n
144
REVIEW using Data Exchange
wait for window to appear then wait for window to disappear © b y H a r v e y E . H a h n
145
REVIEW using Data Exchange
send keystroke © b y H a r v e y E . H a h n
146
REVIEW using Data Exchange
send keystroke (DOWN key) © b y H a r v e y E . H a h n
147
REVIEW using Data Exchange
send keystroke (identifier--“a” key) © b y H a r v e y E . H a h n
148
REVIEW using Data Exchange
click mouse © b y H a r v e y E . H a h n
149
REVIEW using Data Exchange
compare if this is desired filename if not, send DOWN key, and compare next filename © b y H a r v e y E . H a h n
150
REVIEW using Data Exchange
© b y H a r v e y E . H a h n
151
REVIEW using Data Exchange
© b y H a r v e y E . H a h n
152
REVIEW using Data Exchange
send keystroke © b y H a r v e y E . H a h n
153
REVIEW using Data Exchange
wait for window to appear then wait for window to disappear © b y H a r v e y E . H a h n
154
REVIEW using Data Exchange
send keystroke © b y H a r v e y E . H a h n
155
REVIEW using Data Exchange
send keystroke © b y H a r v e y E . H a h n
156
REVIEW using Data Exchange
send keystroke alternative keystroke © b y H a r v e y E . H a h n
157
REVIEW using Data Exchange
OPTIONAL: send keystroke © b y H a r v e y E . H a h n
158
REVIEW using Data Exchange
OPTIONAL: send keystroke © b y H a r v e y E . H a h n
159
REVIEW using Data Exchange
OPTIONAL: send keystroke © b y H a r v e y E . H a h n
160
Thanks for attending! © b y H a r v e y E . H a h n
161
Q & A © b y H a r v e y E . H a h n
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.