Here is the code, this may help. AHK runs and opens the POS (Point of Sale, not Piece of..) and then saves 3 reports (hence me needed the default save path IF it changes somehow), then invokes the sendEmail program. So the folder save path is rendered in AHK, sendEmail really doesnt do anything but literally send the files, specified by name, to the intended user.
Code: Select all
/*
This script will query and save: Flash, Detailed Daily & General Hourly Reports in CRE and then email them to the Client.
sendEmail http://caspian.dotconf.net/menu/Software/SendEmail/ [Download the sendEMail-v156.zip]
SETUP-----------SETUP------------SETUP
-Install AutoHotKey located in the sendEmail.zip file
-Create 'C:\sendEmail' folder and extract the SendEmail files here, right click on the sendEmail.exe and run as Administrator to install
-Place the EmailReports_MASTERv4.ahk file in the C:\sendEmail
-Date_time code
CurrentDate := A_Now
CurrentDate += -1, D
FormatTime, TimeString, %CurrentDate%, M/d/yyyy
Send, %TimeString%
CurrentDate := A_Now
FormatTime, TimeString, %CurrentDate%, M/d/yyyy
Send, %TimeString%
-From:
-To:
*/
Process, Close, CRE2004.exe ; Close the program
Process, Exist, CRE2004.exe ; check to see if CRE2004.exe is running
If (ErrorLevel = 0) ; If it is not running
{
DetectHiddenWindows, Off ; don't close the hidden windows, which could be background programs/processes you want running
SetTitleMatchMode, 2 ; 2: A window's title can contain WinTitle anywhere inside it to be a match.
WinGet WindowList , List
Loop %WindowList%
{
WinGetClass, WindowClass, % "ahk_id" WindowList%A_Index%
If WindowClass not in Progman,Button,Shell_TrayWnd
WinClose,% "ahk_id " WindowList%A_Index%,,,autohotkey.exe Cash Register Express
}
; SetWorkingDir, D:\My Folder\Temp
FileDelete, C:\Reports\*.* ; Will delete all files in C:\Reports\ -Folder
FileRemoveDir, C:\Reports ; Will remove the Reports Folder
FileRecycleEmpty, C:\
FileCreateDir, C:\Reports
SetWorkingDir, C:\Reports
Run, "C:\Program Files (x86)\CRE.NET\CRE2004" ; Executes CRE
Sleep, 10000 ; Places code on hold til the program starts
WinActivate, Settlement Pending
SetKeyDelay, 5000 ; delays keystroks by a 2 seconds
Send, !o{Backspace}{Backspace}
WinActivate, Cash Register Express
SetKeyDelay, 700
Send, !fvdW1{tab}01{enter}4k ;- this will get to the Friendly Printer Setup
WinActivate, Printer Setup
Send, {tab}c!x ; Saves CutePDF as Default Printer
Send, 5l ; Moves to Reporting Screen
WinActivate, Reporting
Send, ff ; To Flash Report
Send, {tab}{tab}{tab}{tab} ; Tabs to Date field
CurrentDate := A_Now
CurrentDate += -1, D
FormatTime, TimeString, %CurrentDate%, M/d/yyyy
Send, %TimeString%
Send, {tab}{tab}
CurrentDate := A_Now
FormatTime, TimeString, %CurrentDate%, M/d/yyyy
Send, %TimeString%
Send, !p
Sleep, 10000
WinActivate, Save As
Sleep, 7000
Send, !n
SetKeyDelay, 700
Send, Flash_Report_TEST1_
SetKeyDelay, 700
CurrentDate := A_Now
CurrentDate += -1, D
FormatTime, TimeString, %CurrentDate%, M-d-yyyy
Send, %TimeString%
Send, !s
SetKeyDelay, 700
WinActivate, Reporting
Send, {tab}{tab}{tab}{tab}
Send, dd ; Moves to Detailed Daily Report
Send, !d
WinActivate, Detailed Daily Report
Send, !p
Sleep, 10000
WinActivate, Save As
; Send, {tab}{down}L{enter}{tab}{tab}R{enter}
; FileSelectFolder, Folder, C:\Reports, 0,
Send, !n
SetKeyDelay, 700
Send, Detailed_Daily_Report_TEST1_
CurrentDate := A_Now
CurrentDate += -1, D
FormatTime, TimeString, %CurrentDate%, M-d-yyyy
Send, %TimeString%
Send, !s!x
SetKeyDelay, 700
WinActivate, Reporting
Send, {tab}{tab}{tab}{tab}{tab}G
Send, !p
Sleep, 10000
WinActivate, Save As
Send, !n
SetKeyDelay, 700
Send, General_Hourly_Report_TEST1_
CurrentDate := A_Now
CurrentDate += -1, D
FormatTime, TimeString, %CurrentDate%, M-d-yyyy
Send, %TimeString%
Send, !s
WinActivate, Reporting
Send, !x4k{tab}t!x!x
; sendEmail code
FileDelete, C:\sendEmail\EmailReport.bat
now := A_Now
FormatTime, today, %now%, M-d-yyyy
now += -1, D
FormatTime, yesterday, %now%, M-d-yyyy
; MsgBox today:`n%today%`n`nyesterday:`n%yesterday%
FileAppend,
(
sendEmail -o tls=yes -f (HIDDEN INFO) -u "TEST1 - Flash, Daily & Hourly Reports" -m "Flash Report, Detailed Daily & General Hourly Reports for TEST1 are attached" -a C:\Reports\Flash_Report_TEST1_%yesterday%.pdf -a
C:\Reports\Detailed_Daily_Report_TEST1_%yesterday%.pdf -a C:\Reports\General_Hourly_Report_TEST1_%yesterday%.pdf -vv
), C:\sendEmail\EmailReport.bat
Sleep, 2000
run, %comspec%
Sleep, 3000
WinActivate, Administrator: C:\Windows\system32\cmd.exe
SetKeyDelay, 300
Send, CD C:\sendEmail{enter}
Send, EmailReport.bat{enter}
Sleep, 7000
WinActivate, Administrator: C:\Windows\system32\cmd.exe
Send, exit{enter}
}
Else ; If it is running, ErrorLevel equals the process id for the target program (CRE2004).
{
WinActivate, Cash Register Express
SetKeyDelay, 500
Send, !fx
Sleep, 7000
Process, Exist, CRE2004.exe ; check to see if CRE2004.exe is running
If (ErrorLevel = 0) ; If it is not running
DetectHiddenWindows, Off ; don't close the hidden windows, which could be background programs/processes you want running
SetTitleMatchMode, 2 ; 2: A window's title can contain WinTitle anywhere inside it to be a match.
WinGet WindowList , List
Loop %WindowList%
{
WinGetClass, WindowClass, % "ahk_id" WindowList%A_Index%
If WindowClass not in Progman,Button,Shell_TrayWnd
WinClose,% "ahk_id " WindowList%A_Index%,,,autohotkey.exe Cash Register Express
}
FileDelete, C:\Reports\*.* ; Will delete all files in C:\Reports\ -Folder
FileRemoveDir, C:\Reports ; Will remove the Reports Folder
FileRecycleEmpty, C:\
FileCreateDir, C:\Reports
SetWorkingDir, C:\Reports
Run, "C:\Program Files (x86)\CRE.NET\CRE2004" ; Executes CRE
Sleep, 10000 ; Places code on hold til the program starts
WinActivate, Settlement Pending
SetKeyDelay, 5000 ; delays keystroks by a 2 seconds
Send, !o{Backspace}{Backspace}
WinActivate, Cash Register Express
SetKeyDelay, 700
Send, !fvdW1{tab}01{enter}4k ;- this will get to the Friendly Printer Setup
WinActivate, Printer Setup
Send, {tab}c!x ; Saves CutePDF as Default Printer
Send, 5l ; Moves to Reporting Screen
WinActivate, Reporting
Send, ff ; To Flash Report
Send, {tab}{tab}{tab}{tab} ; Tabs to Date field
CurrentDate := A_Now
CurrentDate += -1, D
FormatTime, TimeString, %CurrentDate%, M/d/yyyy
Send, %TimeString%
Send, {tab}{tab}
CurrentDate := A_Now
FormatTime, TimeString, %CurrentDate%, M/d/yyyy
Send, %TimeString%
Send, !p
Sleep, 10000
WinActivate, Save As
; Send, {tab}{down}L{enter}{tab}{tab}R{enter}
; FileSelectFolder, Folder, C:\Reports, 0,
Sleep, 4000
Send, !n
SetKeyDelay, 700
Send, Flash_Report_TEST1_
SetKeyDelay, 700
CurrentDate := A_Now
CurrentDate += -1, D
FormatTime, TimeString, %CurrentDate%, M-d-yyyy
Send, %TimeString%
Send, !s
SetKeyDelay, 700
WinActivate, Reporting
Send, {tab}{tab}{tab}{tab}
Send, dd ; Moves to Detailed Daily Report
Send, !d
WinActivate, Detailed Daily Report
Send, !p
Sleep, 10000
WinActivate, Save As
Sleep, 7000
Send, !n
SetKeyDelay, 700
Send, Detailed_Daily_Report_TEST1_
CurrentDate := A_Now
CurrentDate += -1, D
FormatTime, TimeString, %CurrentDate%, M-d-yyyy
Send, %TimeString%
Send, !s!x
SetKeyDelay, 700
WinActivate, Reporting
Send, {tab}{tab}{tab}{tab}{tab}G
Send, !p
Sleep, 10000
WinActivate, Save As
Sleep, 7000
Send, !n
SetKeyDelay, 700
Send, General_Hourly_Report_TEST1_
CurrentDate := A_Now
CurrentDate += -1, D
FormatTime, TimeString, %CurrentDate%, M-d-yyyy
Send, %TimeString%
Send, !s
WinActivate, Reporting
Send, !x4k{tab}t!x!x
; sendEmail code
FileDelete, C:\sendEmail\EmailReport.bat
now := A_Now
FormatTime, today, %now%, M-d-yyyy
now += -1, D
FormatTime, yesterday, %now%, M-d-yyyy
; MsgBox today:`n%today%`n`nyesterday:`n%yesterday%
FileAppend,
(
sendEmail -o tls=yes -f n (HIDDEN INFO) -u "TEST1 - Flash, Daily & Hourly Reports" -m "Flash Report, Detailed Daily & General Hourly Reports for TEST1 are attached" -a C:\Reports\Flash_Report_TEST1_%yesterday%.pdf -a
C:\Reports\Detailed_Daily_Report_TEST1_%yesterday%.pdf -a C:\Reports\General_Hourly_Report_TEST1_%yesterday%.pdf -vv
), C:\sendEmail\EmailReport.bat
Sleep, 2000
run, %comspec%
Sleep, 3000
WinActivate, Administrator: C:\Windows\system32\cmd.exe
SetKeyDelay, 300
Send, CD C:\sendEmail{enter}
Send, EmailReport.bat{enter}
Sleep, 7000
WinActivate, Administrator: C:\Windows\system32\cmd.exe
Send, exit{enter}
}