© 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h...

162
© 2 0 0 9 b y H a r v e y E . H a h n S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington Heights, Illinois

Transcript of © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h...

Page 1: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

© 2 0 0 9 b y H a r v e y E . H a h n

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

Page 2: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

PresenterPresenter

Harvey E. Hahn

Former Manager,

Technical Services,

Arlington Heights

Memorial LibraryArlington Heights, Illinois

Page 3: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Program overviewProgram 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

Page 4: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Some

Scripting

“Secrets”

Page 5: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

PurposePurpose

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

Page 6: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

What is a script?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

Page 7: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

What is “dumb” scripting?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

Page 8: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

What is “smart” scripting?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

Page 9: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Why use scripts?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 :Result :• Increased efficiency• Increased productivity

Page 10: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Script language comparisonScript 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

Page 11: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Other helpful freeware toolsOther 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.)

Page 12: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

FRHEDFRHED

Page 13: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

IrfanViewIrfanView

Page 14: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Successful scripting “secrets”Successful scripting “secrets”

• Typing keystrokes

• “Where am I?”

• Window coordinates

• Clicking buttons / tabs / icons• WYSIWYG—not! (getting window data)

Page 15: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Typing keystrokesTyping 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

Page 16: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Typing keystrokesTyping 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 )

Page 17: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Typing keystrokesTyping keystrokes

• More efficient approach:

Func Type( $Text )

Send( $Text )

Sleep(400) ; add pause after sending text

EndFunc

. . .

Type( “John{ENTER}” )

Type( “Smith{ENTER}” )

Page 18: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Typing keystrokesTyping keystrokes

• Millennium scripting tip:

Always first try using a keyboard shortcut (before trying mouse clicks) because it’s the easiest and most reliable technique

Page 19: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Typing keystrokesTyping keystrokes

• Millennium keyboard equivalents:

#100743 – function keys

#100742 – general shortcut keys

#100535-100542 – window controls and associated shortcut

keys

Page 20: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Typing keystrokes Millennium keyboard equivalentsTyping keystrokes Millennium keyboard equivalents

Page 21: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Typing keystrokes Millennium keyboard equivalentsTyping keystrokes Millennium keyboard equivalents

Page 22: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Typing keystrokes Millennium keyboard equivalentsTyping keystrokes Millennium keyboard equivalents

Page 23: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

“Where am I?”“Where am I?”

• Getting the title of the active window

Why?

Identify various windows (error,processing, get info from user,

etc.)

Page 24: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

“Where am I?”“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!

Page 25: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

“Where am I?”“Where am I?”

• Waiting for a window to appear

Tip:• Watch for possible “surprise” appearance

of an error message window• These are undocumented!

Page 26: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

“Where am I?”“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)

Page 27: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

“Where am I?”“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!

Page 28: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

“Where am I?”“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)

Page 29: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

“Where am I?”“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

Page 30: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

“Where am I?”“Where am I?”

• Distinguish windows with same titles

“C” “D”

Page 31: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

“Where am I?”“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!

Page 32: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Window coordinatesWindow coordinates

• The screen is the entire desktop

• A window is placed somewhere on the screen

• A Millennium window usually covers the entire screen

Page 33: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Window coordinatesWindow 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

Page 34: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Window coordinatesWindow coordinates

98

79

79

98

Page 35: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Window coordinatesWindow 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!

Page 36: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Window coordinatesWindow 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

Page 37: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Window coordinatesWindow coordinates

Page 38: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Window coordinatesWindow coordinates

Page 39: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Clicking buttons/tabs/iconsClicking 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 )

Page 40: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Clicking buttons/tabs/iconsClicking 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

Page 41: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Clicking buttons/tabs/iconsClicking buttons/tabs/icons

Window-based coordinates

Page 42: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Clicking buttons/tabs/iconsClicking buttons/tabs/icons

Screen-based coordinates

Page 43: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Clicking buttons/tabs/iconsClicking buttons/tabs/icons

• To keep coordinates inside of a window stable, they should always be relative to that window (not to the screen)

Page 44: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Clicking buttons/tabs/iconsClicking buttons/tabs/icons

• To resolve any screen/window conflicts, offsets are needed from the screen edges to a window’s upper left corner (“origin”)

Page 45: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Clicking buttons/tabs/iconsClicking buttons/tabs/icons

X offset

Y offset

Page 46: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Clicking buttons/tabs/iconsClicking 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.

Page 47: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Clicking buttons/tabs/iconsClicking buttons/tabs/icons

Page 48: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Clicking buttons/tabs/iconsClicking buttons/tabs/icons

Page 49: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Clicking buttons/tabs/iconsClicking buttons/tabs/icons

Page 50: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

• “Reading” data off the screen is often the most difficult and challenging task when writing scripts to automate Millennium

Page 51: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

• Select (highlight) specific text

How?• Use the standard Windows “select all” command

(Ctrl-a)• Depending on the screen context, this may select

the contents of a single row or the contents of an entire bib, item, order, or patron record

Page 52: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

• Use the clipboard

AutoIt 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

Page 53: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

Example

Func GetHighlightedData() ClipPut( “” ) ; always clear the clipboard first! TypeCtl ( “c” ) ; copy highlighted data to the clipboard TypeCtl ( “c” ) ; duplicate needed for reliability (why??) $HighlightedData = ClipGet() ; put data into a variable Return $HighlightedData

EndFunc. . .TypeCtl( “a” ) ; select (highlight) all editable text$text = GetHighlightedData()

Page 54: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

• 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

Page 55: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

Page 56: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

Page 57: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

Page 58: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

Page 59: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

Page 60: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

Page 61: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

check for this text

Page 62: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

Page 63: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

Page 64: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

• Millennium scripting tip:

• To find a highlighted row in a table, don’t loop through every pixel in a column, looking for the color

• Note: Cell data in tables is 16 pixels apart. For speed purposes, check just every 8th (or even 16th) pixel in a blank area of a given data column

Page 65: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

• Dropdown listsElements in these lists cannot be “read” by scripts

• 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

Page 66: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

• 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 # 100541)

Algorithm• Choose the list (usually an Alt-key combination)• Send( “c” ) or Send( “i” ) or Send( $choice )

Page 67: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

Page 68: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

No letters, yet works!

Note: first element is NOT default!

Page 69: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

• 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

Page 70: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

Page 71: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

END key moved to last element

Page 72: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

WYSIWYG—not! (getting window data)WYSIWYG—not! (getting window data)

• 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

Page 73: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Getting item dataGetting item data

Page 74: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Getting item dataGetting item data

Page 75: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Getting item dataGetting item data

Page 76: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Getting item dataGetting item data

Page 77: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Getting item dataGetting item data

hex 20 = space

Page 78: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Getting item dataGetting item data

Page 79: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Getting item dataGetting item data

Page 80: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Getting item dataGetting item data

hex 09 = TAB (not spaces) hex 0d 0a = CRLF

(end of line)

Page 81: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Getting bib dataGetting bib data

Page 82: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Getting bib dataGetting bib data

Page 83: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Getting bib dataGetting bib data

Page 84: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Getting bib dataGetting bib data

Page 85: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Getting bib dataGetting bib data

Page 86: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Getting bib dataGetting bib data

hex 20 = space

Page 87: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Getting bib dataGetting bib data

Page 88: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Getting bib dataGetting bib data

Page 89: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Getting bib dataGetting bib data

hex 09 = TAB (not spaces)

Page 90: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Getting bib dataGetting bib data

hex 09 = TAB (not spaces)

hex 7c = subfield_delimiter

(pipe)

hex 0d 0a = CRLF (end of line)

Page 91: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Changing/deleting dataChanging/deleting data

• Fixed fields:• Click at end of fixed field table• Ctrl-Home to beginning of first fixed field• "tab to a field" approach

Page 92: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Changing/deleting dataChanging/deleting data

• Variable fields (top-down):• Click at end of fixed field table• Tab once to first variable field• "read a line at a time" approach (downward)

(using Home and Shift-End to get each line)

Page 93: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Changing/deleting dataChanging/deleting data

• Variable fields (bottom-up):• Ctrl-End to end of last variable field• Home to beginning of field• "read a line at a time" approach (upward)

(using Home and Shift-End to get each line)

Page 94: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Changing/deleting dataChanging/deleting data

• Millennium scripting tip:

To replace data in a variable field, rather than fiddle with insertions and such, it's sometimes easier to delete the field and then add the modified version as a new field

Page 95: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Next-to-last scripting “secret”Next-to-last scripting “secret”

• Using a script recorder is NOT cheating!

• Enables you to establish a starting point from which you can adapt as necessary

Page 96: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Final scripting “secret”Final scripting “secret”

• Reuse code written by yourself and others -- there’s no point in reinventing the wheel!

• 2009 Conference program web site:

FavFuncs.au3

Page 97: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data Exchange

REVIEW using Data Exchange

Page 98: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

OPTIONAL:

check title for correct window

Page 99: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

OPTIONAL:

check pixels for correct screen

Page 100: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

send keystroke

Page 101: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

send keystroke (DOWN key)

Page 102: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

send keystroke (END key)

Page 103: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

send keystroke (ENTER key)

Page 104: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

click mouse

Page 105: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

send keystroke (TAB key)

Page 106: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

send keystroke (SHIFT-HOME key)

Page 107: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

send keystrokes (IP address)

Page 108: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

send keystroke

Page 109: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

send keystrokes:

Alt-u user_name Alt-p password

Page 110: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

send keystroke

Page 111: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

wait for window to appear

then wait for window to disappear

Page 112: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

send keystroke

Page 113: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

send keystroke (DOWN key)

Page 114: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

send keystroke (identifier--“a” key)

Page 115: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

click mouse

Page 116: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

compare if this is desired filename

if not, send DOWN key, and compare next filename

Page 117: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

Page 118: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

Page 119: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

send keystroke

Page 120: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

wait for window to appear

then wait for window to disappear

Page 121: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

send keystroke

Page 122: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

send keystroke

Page 123: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

send keystroke

alternative keystroke

Page 124: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

OPTIONAL:

send keystroke

Page 125: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

OPTIONAL:

send keystroke

Page 126: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

REVIEW using Data ExchangeREVIEW using Data Exchange

OPTIONAL:

send keystroke

Page 127: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Why two parts in this talk?Why two parts in this talk?

• My vision:

To combine the Innovative system, AutoIt scripts, J scripts, and one’s local PC to create a powerful fusion of technologies for creating, managing, manipulating, and interpreting Innovative data

Page 128: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Some

Statistics

“Secrets”

Page 129: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

PurposePurpose

• To introduce the J programming language as a powerful alternative and addition to Excel for handling exported Millennium data

Page 130: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

What is “J”?What is “J”?

• An improved derivative of APL

• Invented in 1989 by Ken Iverson, who also invented APL in early 1960’s

• Availability (free): http://www.jsoftware.com

Page 131: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

What is “J”?What is “J”?

• Like APL, J operates on an entire array as a single entity rather than thinking of the array as a collection of separate elements

• J views nearly everything as an array

Page 132: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

What is “J”?What is “J”?

• Terms for arrays of increasing rank:• atom – a single element (rank 0)• list – one or more atoms (rank 1)• table – one or more lists (rank 2)• report – one or more tables (rank 3+)

Page 133: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Analogy of J to geometryAnalogy of J to geometry

• atom point (0 dimensions)

• list line (1 dimension)

• table plane (2 dimensions)

• report cube, hypercube, etc. (3+ dimensions)

Page 134: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Another J analogyAnother J analogy

• atom

• list

• table

• report

Page 135: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

What is “J”?What is “J”?

• Expanding upon the arithmetic symbols (+, -, etc.), J uses nearly all symbols (and some letters) on an ASCII keyboard to represent operations on arrays

• Each symbol also has 2 inflected forms, appending either a period or a colon

Page 136: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

What is “J”?What is “J”?

• Elements in a programming command can be any of these parts of language:• nouns• verbs• adverbs• conjunctions• gerunds

Page 137: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

What is “J”?What is “J”?

• There are only two basic command formats—everything else is a variation on these:

• verb noun (monadic - 1 arg)

• noun verb noun (dyadic - 2 args)

• Note: A noun argument can actually contain multiple arguments or parameters, if needed; a verb can be a J primitive or something you (or others) have written (because J is extensible)

Page 138: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

What is “J”?What is “J”?

• Both forms resolve to a noun, which can be substituted in a larger command:

( noun verb noun ) verb ( verb noun )

noun verb noun

Page 139: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

What is “J”?What is “J”?

• Often, but certainly not always, the righthand noun argument is data and the lefthand noun argument (if any) controls how the verb acts on the data

Page 140: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

What is “J”?What is “J”?

• The key difference in these noun arguments from other programming languages is that not only can they be single numeric or literal values but they can also be entire arrays!

• This is the main “secret” of J’s power

Page 141: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

What is “J”?What is “J”?

• A second “secret” of J’s power is that the explicit array looping needed in other languages is built into J’s commands

• This considerably simplifies the writing of scripts and helps mentally focus on the “big picture”

Page 142: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

What is “J”?What is “J”?

• Because J is so terse, often a whole program (or portions) can be written sideways rather than vertically!

• Here is an example of a whole program within a single line of code (frequencies of subject headings in a catalog):

sh7=.|:((|:~.(/:{)sh),(<&>#;.1~:(/:{)sh))

Page 143: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

What is “J”?What is “J”?

Page 144: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

What is “J”?What is “J”?

• Downsides:• Looks like “Martian”• Rather “geeky”• Huge amount of documentation, but very

difficult to find specific information• Steep learning curve may intimidate

beginners• Major paradigm shift in thinking

Page 145: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

What is “J”?What is “J”?

• Upsides:• Can do a lot with very little code• Availability of a very complete suite of

“assisting” applications, most written in J (plotting, forms and controls, spreadsheet, database, regular expressions, etc.)

• Size of arrays is limited only by amount of memory and disk space available

• So-called “boxed” arrays can contain mixed numeric and literal data

Page 146: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Examples of J primitivesExamples of J primitives

i. n create list of integers from 0 to n-1

|. reverse order of items in array

|: transpose (flip) rows/cols in table

/:~ sort items in list in ascending order

~. dedupe items in list

, append two sets of items

=: global assignment ( =. is local )

Page 147: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Simple J program/scriptSimple J program/script

br3=: ~. /:~ (br1,br2)

• br1 and br2 are two lists of bib rec numbers that have already been read from disk

• Meaning of script (executed right-to-left):• Append br2 to br1 to form a single large list• Sort this list• Dedupe the list• Assign (globally) the list to variable br3

Page 148: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

More examples of JMore examples of J

• You can give your own names to verbs:

] revfile1=: 1 + i.10

1 2 3 4 5 6 7 8 9 10

] revfile2=: 2 3 5 8

2 3 5 8

remove=: -. NB. usually known as “not”

] result=: revfile1 remove revfile2 1 4 6 7 9 10

Page 149: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

More examples of JMore examples of J

• You can create your own verbs: shfreq=: 3 : 0 NB. “x” is LH arg, “y” is RH arg of verb:

sh2=. (/:{) y NB. sorted list sh3=. # ;.1 ~: sh2 NB. freq’s sh4=. |: ~. sh2 NB. unique SH’s sh5=. < every sh3 NB. counts sh6=. |: (sh4,sh5) NB. combine SH’s & counts )

• Use new verb like any other J verb: freqlist=: shfreq sh NB. sh = file of SH’s

Page 150: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

More examples of JMore examples of J

• You can use verbs that others have created:

updatewith is a verb written by someone proficient in J at my request

(see updatemasterfile.ijs on 2009 Conference program web site)

It appends a column of data to an existing (“master”) table, matching row data according to the keys in the first column of both files (this provides a workaround for III’s zero suppression in reports)

Page 151: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

More examples of JMore examples of J

• Example of monthly statistics use:

load '~user\temp\updatemasterfile.ijs'

master=: jpath '~user\data\master.csv'

newdata=: jpath '~user\data\month01.csv'

master updatewith newdata

• Note: updatemasterfile.ijs script contains 2 verbs with 21 lines of code

Page 152: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

More examples of JMore examples of J

• Example of use with patron checkouts:

load '~user\temp\updatemasterfile.ijs'

master=: jpath '~user\data\master.csv'

newdata=: jpath '~user\data\snapshot01.csv'

master updatewith newdata

• Note: this can be subsequently used to calculate circulation statistics between two or more “snapshot” dates

Page 153: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

More examples of JMore examples of J

• It’s also possible to “GUI-fy” the previous simple scripts by having two dropcombo boxes of file directories that a staff member could choose from—without having to know or learn J themselves!

Page 154: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Appetite whetted for J?Appetite whetted for J?

• J has enough array and mathematical power to keep you learning for a lifetime

• J can be used independently of Excel

• J can be used in conjunction with Excel (there are also direct interfaces with Excel)

• I hope that I’ve interested you enough in J so that you can…

Page 155: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

J J

Pick up the torch and go for it!

Page 156: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

More informationMore information

• ---- AHML web site ---- (as long as it’s available)

http://www.ahml.info/oml

• Links: Scripts Using AutoIt

Scripts Using J (including my “Beginning J”)

Page 157: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

More informationMore information

• ---- WILIUG presentations ----

• More about AutoIt scripting (Jun 2006): http://www.wiliug.org/meetings/2006/6_06.html

• More about the J language (Jun 2009): http://www.wiliug.org/meet.html

Page 158: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

More informationMore information

• ------ Discussion groups ------

• Script language forums: http://www.autoitscript.com/forum/index.php? http://www.autohotkey.com/forum/ http://pgmacros.invisionzone.com/ (Macro Express)

• J language forums/groups: http://www.jsoftware.com/forums.htm http://groups.google.com/group/J-Programming

Page 159: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Email addressesEmail addresses

• After May 2009:

[email protected] or

[email protected]

Page 160: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Thanks for attending!Thanks for attending!

Page 161: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.

Q & AQ & A

Page 162: © 2 0 0 9 b y H a r v e y E. H a h n S ome S ecrets of S uccessful S cripting and S tatistics h arvey h ahn Arlington Heights Memorial Library Arlington.