Sunday, April 7, 2019

email - Create an AHK to do a specific task automatically


I have to open a program named "EDI Tracker.exe" and browse for an excel file"867_CCM.xls" and press enter and wait for the program to process the excel file. The processing time may differ based upon size of the file. Then after the processing is finished a message box with title "Result" will pop up saying "Congratulations! No Failure found". As this message box appears I will print screen and email the screen shot in outlook along with the excel attachment.
The point is this is my daily routine and I want to automate it. So I am using AHK. Below is my script so far


Run, open "C:\Program Files\EDI867 Tracer\EDITracker.exe"
sleep, 1500
MouseClick, left, 1299, 85
Send, "867_CCM.xls
Send {Enter}
Return

Now I want the script to wait until the message box appears and as soon as it appears I want to do print screen and email the screenshot and the excel file mentioned above as an attachment to specific people.


P.S: I always keep the excel file in my desktop.


Answer



SetTitleMatchMode, 2
WinWaitActive, Congratulations ; match on a partial title is more readable
SendInput {PrintScreen}
; pseudo code... will need modified...
; Use IrfanView or other utility to save the clipboard to a file
; For IrfanView use /silent /clippaste /cmdexit options
filepath := "c:\yourpath\to\save\file\at\screenshot.jpg"
cmdToRun := "c:\program files (x86)IrfanView\i_view32.exe " . filePath . ""
runwait, %cmdtoRun%

This should get your screenshot saved to disk.


For the remaining tasks to send an email with the attachments you may want to transition to a .vbs file that invokes Outlook, creates a new email and attaches the files you want to the email before sending. Look elsewhere for those examples. You would be able to run the .vbs file from your .ahk script using the run command once the screenshot has been captured.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...