Hello!
Lets just start off with... I love AHK. I am pretty new but have made about 30 or so scripts that have helped automate many simple but repetitive tasks for the company I work for. Feedback is greatly appreciated. Like to learn.
I want to automate pulling data from this application. It's a Tera Term session via an SSH connection to a county system. Main reason I am doing it is because we need an easy way to capture certain screens and save it into our electronic imaging system.
The issue I am having is as follows. I want to parse out the lower menu portion of the screen that I am capturing to the clipboard. I was trying to use regexreplace but I can only get it to work on a couple of the strings.
The screen shot below is what I am capturing. I have different menu options depending on the screen but most are very similar.
I was wondering if there are restrictions that I am just overlooking in the documentation.
Can I not load the whole section into a variable... are there issues with spaces? I dont want to lose the format of the clipboard section. Ideas? Open comments about the code structure?
Once I get the menu portion off I want to use the "continued.." statement that will be left as the last line to know if I need to navigate to the next screen.
Screen Start.... (the formatting of this is all wacked out due to being pasted here.) in red is what I want to work with.
- - Property Account Summary (R2040816) - -
Property: R2040816 2S132CD-00800 088.10 HOOBER, ROBERT & DIANA (556979)
CRESTWOOD HEIGHTS, LOT 6, ACRES .19 15646 SW WILLOW CT
SHERWOOD, OR 97140
All Batch: Inq - Eff Date Paid: 11/16/2009
ID# Bill ID Levied Tax Tax Paid Interest Amount Paid Date Paid
--- -------------- ---------- ---------- --------- ----------- -----------
1. 1999.23681 0 2,119.44 2,055.86 <63.58> 2,055.86 11/15/99
2. 2000.56468 0 2,151.71 2,087.16 <64.55> 2,087.16 11/09/00
3. 2001.158096 0 2,358.36 2,287.61 <70.75> 2,287.61 11/09/01
4. 2002.147255 0 2,378.20 2,306.85 <71.35> 2,306.85 10/23/02
5. 2003.147949 0 2,421.00 2,420.59 161.81 2,582.40 09/10/04
Write Off 0.41
6. 2004.282804 0 2,453.93 2,380.31 <73.62> 2,380.31 11/15/04
7. 2005.287448 0 2,480.70 2,406.28 <74.42> 2,406.28 11/10/05
8. 2006.292672 0 2,497.49 2,422.57 <74.92> 2,422.57 11/13/06
*** Continued ***
qqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqq
(N)ext Page x (D#) Down x (B)ottom x (.) More
qqqqqqqqqqqqqqqqqqqvqqqqqqqqqqqqqqqqqqqvqqqqqqqqqqqqqqqqqqqvqqqqqqqqqqqqqqqqqqqq
Enter Option From Above, or or 'X' to Exit: __
Screen End...
Here is my code... (about 70% done)
Code:
; Assembled by Shane Saviers
; Version: 1.1
; Dated: 10/20/2009
;TEST PARCEL 2028862
DelMenu1 :=
(
"qqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqq"
)
DelMenu2 :=
(
" (N)ext Page x (D#) Down x (B)ottom x (\.) More"
)
DelMenu3 :=
(
"qqqqqqqqqqqqqqqqqqqvqqqqqqqqqqqqqqqqqqqvqqqqqqqqqqqqqqqqqqqvqqqqqqqqqqqqqqqqqqqq"
)
DelMenu4 :=
(
"Enter Option From Above\, or or 'X' to Exit: __"
)
#SingleInstance force
; Interface GUI!
Gui +AlwaysOnTop
Gui, 1:Font, s8, Arial
Gui, Add, radio, vTicor, Ticor
Gui, Add, radio, vFidelity, Fidelity
Gui, Add, radio, vChicago, Chicago
Gui, Add, radio, vLawyers, Lawyers
Gui, Add, Text,, Parcel Number:
Gui, Add, Edit, vParcelNumber
Gui, Add, Button, w120 default, Login
Gui, Add, Button, w120, Auto
Gui, Add, Button, w120, Clear
Gui, Add, Button, w120, Get
Gui, Add, Button, w120, View
Gui, Show, w140 h285 x742-y78, WATAX
return
GuiClose:
Gui Destroy
ExitApp
ButtonClear:
clipboard =
return
;Scrape Screen contents.
ButtonGet:
Gui, Show, w140 h285 x742-y78, WATAX
WinWait, 111.222.333.44:00 - Tera Term VT,
IfWinNotActive, 111.222.333.44:00 - Tera Term VT, , WinActivate, 111.222.333.44:00 - Tera Term VT,
WinWaitActive, 111.222.333.44:00 - Tera Term VT,
clipboard = %clipboard%
ClipSaved := clipboard
sleep 500
Send, {ALTDOWN}{ALTUP}{RIGHT}{UP}{UP}{UP}{ENTER}
send, {ALTDOWN}{ALTUP}{RIGHT}{UP}{UP}{UP}{UP}{ENTER}
clipboard = %ClipSaved%`r`n%clipboard%
;Replace spacing with underscore character
ClipboardParse := RegExReplace(clipboard,DelMenu4,"")
;ClipboardParse := RegExReplace(clipboard,DelMenu2,"")
;ClipboardParse := RegExReplace(clipboard,DelMenu3,"")
;ClipboardParse := RegExReplace(clipboard,DelMenu4,"")
msgbox %ClipboardParse%
return
ButtonView:
FileDelete, %A_MyDocuments%_%Username%.html
sleep 2500
FileAppend,
(
<html>
<head>
<style type="text/css">
h1 {color:#333; background-color: #ddd; padding: 3px 10px;}
p {color:blue}
body {text-align: center;}
#container {margin-left: auto; margin-right: auto; width: 700px; text-align: left; padding: 3px 20px;)
</style>
</head>
<body>
<div id="container">
<h1>Washington County Taxes</h1>
<pre>
<p>
%Clipboard%
</p>
</pre>
</div>
</body>
</html>
), %A_MyDocuments%_%A_Username%.html
sleep 1500
Run, %A_MyDocuments%_%A_Username%.html
Gui, Show, w140 h285, Tax
return
ButtonLogin:
Gui, Submit
If (Ticor = 1)
{
LoginID := "user"
Password := "pass"
}
Else
If (Fidelity = 1)
{
LoginID := "user"
Password := "pass"
}
Else
If (Chicago = 1)
{
LoginID := "user"
Password := "pass"
}
Else
If (Lawyers = 1)
{
LoginID := "user"
Password := "pass"
}
Else
{
msgbox, Please Select Brand
Gui, Show, w140 h285, Tax
return
}
Run, %ProgramFiles%\teraterm\ttermpro.exe /f=\\orportla-apl02\WaTax\WaTax.INI,,UseErrorLevel
If ErrorLevel
{
MsgBox,48,ERROR,Sorry, It appears you don't have Terra Term installed `n`nIf you need assistance please contact PacNW IT.
Exit,
}
Else
;Trim whitespace at the START AND END of a string:
ParcelNumber := RegExReplace(OrderNumber, "(^\s+)|(\s+$)")
;Replace spacing with underscore character
;StringReplace,Name,Name,%A_SPACE%,_,All
WinWait, Tera Term: New connection,
IfWinNotActive, Tera Term: New connection, , WinActivate, Tera Term: New connection,
WinWaitActive, Tera Term: New connection,
send, {ENTER}
WinWait, SSH Authentication,
IfWinNotActive, SSH Authentication, , WinActivate, SSH Authentication,
WinWaitActive, SSH Authentication,
sleep 1000
Send, %LoginID%
sleep 500
Send, {SHIFTDOWN}{TAB}{TAB}{SHIFTUP}
sleep 500
Send, {ENTER}{SPACE}
IfWinNotActive, SSH Authentication Challenge, , WinActivate, SSH Authentication Challenge,
WinWaitActive, SSH Authentication Challenge,
sleep 500
Send, %Password%{ENTER}
WinWait, 111.222.333.44:00 - Tera Term VT,
IfWinNotActive, 111.222.333.44:00 - Tera Term VT, , WinActivate, 111.222.333.44:00 - Tera Term VT,
WinWaitActive, 111.222.333.44:00 - Tera Term VT,
sleep 2500
Send, %Password%{ENTER}
sleep 2000
send, 1{ENTER}
sleep 2000
send, inq{ENTER}
sleep 1500
send, inq{ENTER}
sleep 2000
send, 1{ENTER}
sleep 2000
send, 1{ENTER}
Gui, Show, w140 h285, Tax
return
ButtonAuto:
Gui, Submit
If (Ticor = 1)
{
LoginID := "user"
Password :="pass"
}
Else
If (Fidelity = 1)
{
LoginID := "user"
Password :="pass"
}
Else
If (Chicago = 1)
{
LoginID := "user"
Password :="pass"
}
Else
If (Lawyers = 1)
{
LoginID := "user"
Password :="pass"
}
Else
{
msgbox, Please Select Brand
Gui, Show, w140 h285, Tax
return
}
Run, %ProgramFiles%\teraterm\ttermpro.exe /f=\\orportla-apl02\WaTax\WaTax.INI,,UseErrorLevel
If ErrorLevel
{
MsgBox,48,ERROR,Sorry, It appears you don't have Terra Term installed `n`nIf you need assistance please contact PacNW IT.
Exit,
}
Else
;Trim whitespace at the START AND END of a string:
ParcelNumber := RegExReplace(OrderNumber, "(^\s+)|(\s+$)")
;Replace spacing with underscore character
;StringReplace,Name,Name,%A_SPACE%,_,All
WinWait, Tera Term: New connection,
IfWinNotActive, Tera Term: New connection, , WinActivate, Tera Term: New connection,
WinWaitActive, Tera Term: New connection,
send, {ENTER}
WinWait, SSH Authentication,
IfWinNotActive, SSH Authentication, , WinActivate, SSH Authentication,
WinWaitActive, SSH Authentication,
sleep 1000
Send, %LoginID%
sleep 500
Send, {SHIFTDOWN}{TAB}{TAB}{SHIFTUP}
sleep 500
Send, {ENTER}{SPACE}
IfWinNotActive, SSH Authentication Challenge, , WinActivate, SSH Authentication Challenge,
WinWaitActive, SSH Authentication Challenge,
sleep 500
Send, %Password%{ENTER}
WinWait, 111.222.333.44:00 - Tera Term VT,
IfWinNotActive, 111.222.333.44:00 - Tera Term VT, , WinActivate, 111.222.333.44:00 - Tera Term VT,
WinWaitActive, 111.222.333.44:00 - Tera Term VT,
sleep 2500
Send, %Password%{ENTER}
sleep 2000
send, 1{ENTER}
sleep 2000
send, inq{ENTER}
sleep 1500
send, inq{ENTER}
sleep 3500
send, 1{ENTER}
sleep 2000
send, %ParcelNumber%
send, {ENTER}
Gui, Show, w140 h285, Tax
return
#Persistent
Menu, tray, add
Menu, tray, add, About..., About
Menu, tray, add, Reload Script, Reload
return
; Reload request...
Reload:
Reload
Sleep 1000 ; If successful, the reload will close this instance during the Sleep, so the line below will never be reached.
MsgBox, 1,, The script could not be reloaded. Please try closing and re-opening.
return
; About splash screen!
About:
SplashTextOn, 400, 120, About..., `nThank you for using this script!`n If for some reason you have problems `nwith this script use the "Reload" option and `n if that fails please feel free to contact me at `n shane.saviers@somewhere.com
WinSet, Transparent, 200, About...
WinSet, Style, -0xC00000, About...
Gui, Add, Button, w50 default, OK
Sleep 8000
SplashTextOff
; End of Script...