1.62k likes | 1.82k Views
S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn. Arlington Heights Memorial Library Arlington Heights, Illinois. Harvey E. Hahn Former Manager, Technical Services, Arlington Heights Memorial Library Arlington Heights, Illinois. Presenter. Program overview.
E N D
SomeSecrets of Successful Scripting andStatisticsharveyhahn Arlington Heights Memorial Library Arlington Heights, Illinois © 2 0 0 9 b y H a r v e y E . H a h n
Harvey E. Hahn Former Manager, Technical Services, Arlington Heights Memorial Library Arlington Heights, Illinois Presenter
Program overview • Part 1 • Tips gained from 4 years and over 25,000 lines of AutoIt code (as well as 12 years of writing 152 OCLC macros, including III telnet applications) • Part 2 • Brief “whet your appetite” introduction to the J programming language for processing exported Millennium data
Some Scripting “Secrets”
Purpose • To share helpful patterns, tips, and techniques that you can use in your scripts to automate Millennium
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
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
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
Why use scripts? • 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
Script language comparison • Cost • AutoIt, AutoHotKey,VBScript, and Expect are free • OCLC Macro Language is freely available to OCLC customers only • Macro Express costs $40 per computer • GUI capabilities • AutoIt, AutoHotKey, and Macro Express do windows • VBScript,Expect , and OML do not
Other helpful freeware tools • FRHED(FRee Hex EDitor) http://www.kibria.de/frhed.html • IrfanView(“EAR-fun-view”) (image viewer) http://www.irfanview.com/ • Any text editor(Notepad, Notepad+, NoteTab, Win32Pad, etc.)
Successful scripting “secrets” • Typing keystrokes • “Where am I?” • Window coordinates • Clicking buttons / tabs / icons • WYSIWYG—not! (getting window data)
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
Typing keystrokes • For a Send command to work successfully, a Sleep command needs to be paired with it: Send( “John{ENTER}” ) Sleep( 200 ) Send( “Smith{ENTER}” ) Sleep( 200 )
Typing keystrokes • More efficient approach: Func Type( $Text ) Send( $Text ) Sleep(400) ; add pause after sending text EndFunc . . . Type( “John{ENTER}” ) Type( “Smith{ENTER}” )
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
Typing keystrokes • Millennium keyboard equivalents: #100743 – function keys #100742 – general shortcut keys #100535-100542 – window controls and associated shortcut keys
“Where am I?” • Getting the title of the active window Why? Identify various windows (error, processing, get info from user, etc.)
“Where am I?” • Waiting for a window to appear 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!
“Where am I?” • Waiting for a window to appear Tip: • Watch for possible “surprise” appearance of an error message window • These are undocumented!
“Where am I?” • Waiting for a window to appear How? • Keep checking to see when the title of the window has changed (but sometimes multiple windows have the same title!), or • Wait until the window is “active” (focus) (most common approach)
“Where am I?” • Waiting for a window (or part of a window) to change Why? • Script must wait until a given window is “ready for action” • Script must wait until part of a given window has changed and is “ready for action” • This is one of the most important aspects of GUI scripting!
“Where am I?” • Waiting for a window (or part of a window) to change How? (in AutoIt) • (1) Determine a rectangular area to check • (2) Take a “snapshot” of the area with PixelCheckSum • (3) Keep taking “snapshots” until the pixel checksum for the area changes (compared with the original value)
“Where am I?” • Getting pixel colors of text, background, or images (“worst case” scenario) AutoIt syntax: $hexcolor = Hex( PixelGetColor( $x, $y ), 6 ) 0 = black FFFFFF = white RRGGBB
“Where am I?” • Distinguish windows with same titles “C” “D”
“Where am I?” • Using patterns of pixels to identify characters or positions 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!
Window coordinates • The screen is the entire desktop • A window is placed somewhere on the screen • A Millennium window usually covers the entire screen
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
Window coordinates 98 79 98 79
Window coordinates • Millennium scripting tip: A window must be maximized for consistent coordinates Example of AutoIt syntax: WinSetState( $WinName, "", @SW_MAXIMIZE ) NOTE: This command will even maximize windows which have no maximize button!
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
Clicking buttons/tabs/icons • “Wrapper” function approach: Func ClickAt( $x, $y ) MouseClick( "left", $x, $y, 1, 0 ) Sleep(400) ; add pause after clicking mouse EndFunc . . . ClickAt( 400, 300 )
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
Clicking buttons/tabs/icons Window-based coordinates
Clicking buttons/tabs/icons Screen-based coordinates
Clicking buttons/tabs/icons • To keep coordinates inside of a window stable, they should always be relative to that window (not to the screen)
Clicking buttons/tabs/icons • To resolve any screen/window conflicts, offsets are needed from the screen edges to a window’s upper left corner (“origin”)
Clicking buttons/tabs/icons Y offset X offset
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.
WYSIWYG—not! (getting window data) • “Reading” data off the screen is often the most difficult and challenging task when writing scripts to automate Millennium