1 / 162

S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn

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.

saxton
Download Presentation

S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. Harvey E. Hahn Former Manager, Technical Services, Arlington Heights Memorial Library Arlington Heights, Illinois Presenter

  3. 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

  4. Some Scripting “Secrets”

  5. Purpose • To share helpful patterns, tips, and techniques that you can use in your scripts to automate Millennium

  6. 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

  7. 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

  8. 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

  9. 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

  10. 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

  11. 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.)

  12. FRHED

  13. IrfanView

  14. Successful scripting “secrets” • Typing keystrokes • “Where am I?” • Window coordinates • Clicking buttons / tabs / icons • WYSIWYG—not! (getting window data)

  15. 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

  16. 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 )

  17. Typing keystrokes • More efficient approach: Func Type( $Text ) Send( $Text ) Sleep(400) ; add pause after sending text EndFunc . . . Type( “John{ENTER}” ) Type( “Smith{ENTER}” )

  18. 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

  19. Typing keystrokes • Millennium keyboard equivalents: #100743 – function keys #100742 – general shortcut keys #100535-100542 – window controls and associated shortcut keys

  20. Typing keystrokes Millennium keyboard equivalents

  21. Typing keystrokes Millennium keyboard equivalents

  22. Typing keystrokes Millennium keyboard equivalents

  23. “Where am I?” • Getting the title of the active window Why? Identify various windows (error, processing, get info from user, etc.)

  24. “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!

  25. “Where am I?” • Waiting for a window to appear Tip: • Watch for possible “surprise” appearance of an error message window • These are undocumented!

  26. “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)

  27. “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!

  28. “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)

  29. “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

  30. “Where am I?” • Distinguish windows with same titles “C” “D”

  31. “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!

  32. Window coordinates • The screen is the entire desktop • A window is placed somewhere on the screen • A Millennium window usually covers the entire screen

  33. 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

  34. Window coordinates 98 79 98 79

  35. 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!

  36. 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

  37. Window coordinates

  38. Window coordinates

  39. 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 )

  40. 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

  41. Clicking buttons/tabs/icons Window-based coordinates

  42. Clicking buttons/tabs/icons Screen-based coordinates

  43. Clicking buttons/tabs/icons • To keep coordinates inside of a window stable, they should always be relative to that window (not to the screen)

  44. 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”)

  45. Clicking buttons/tabs/icons Y offset X offset

  46. 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.

  47. Clicking buttons/tabs/icons

  48. Clicking buttons/tabs/icons

  49. Clicking buttons/tabs/icons

  50. WYSIWYG—not! (getting window data) • “Reading” data off the screen is often the most difficult and challenging task when writing scripts to automate Millennium

More Related