Advertisement
TheVideoVolcano

AutoIt Keychobbler WIP

Dec 2nd, 2021 (edited)
2,060
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 3.25 KB | None | 0 0
  1. #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
  2. #AutoIt3Wrapper_Outfile_x64=..\Logbook Email Script.Exe
  3. #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
  4. #include <Date.au3>
  5. #include <Misc.au3>
  6. #include <MsgBoxConstants.au3>
  7.  
  8. Opt("TrayMenuMode", 3)
  9. $sendEmailTrayBtn = TrayCreateItem("Send Email")
  10. $exitTrayBtn = TrayCreateItem("Exit Script")
  11.  
  12. $emailNum = 1
  13. $emailMaxNum = 3
  14.  
  15. $prevWinHandle = ""
  16. Global $prevMousePos
  17.  
  18. func showOriginWin()
  19.  
  20.     WinSetState($prevWinHandle, "", @SW_MAXIMIZE)
  21.     WinActivate($prevWinHandle)
  22.  
  23. EndFunc
  24.  
  25. func resetMousePos()
  26.  
  27. MouseMove($prevMousePos[0], $prevMousePos[1])
  28.  
  29. EndFunc
  30.  
  31. Func sendEmail()
  32.  
  33.  
  34.     Local $coordNewEmailBtn[2] = [24, 104]
  35.     Local $coordSendBtn[2] = [29, 227]
  36.     local $coordHomeTabBtn[2] = [92, 47]
  37.  
  38.     $fpath = 'C:\Users\GeraciR\Desktop\Logbook.docx'
  39.     $toEmail = "ricci07@hotmail.co.uk"
  40.     $subject = "Logbook - " & _Now() & " (" & $emailNum & "/" & $emailMaxNum & ")"
  41.  
  42.  
  43.     ;Before even bothering with running the script, lets check that we have all the files we need
  44.  
  45.     If Not FileExists($fpath) Then
  46.         MsgBox($MB_TOPMOST, "", "The logbook file doesn't exist at " & @CRLF & $fpath & @CRLF & "Script will cease!")
  47.         Exit
  48.     EndIf
  49.  
  50.     $winHandle = WinGetHandle("[CLASS:rctrl_renwnd32]")
  51.     $prevWinHandle = WinGetHandle("[ACTIVE]") ;to go back to original window after doing the email task
  52.     $prevMousePos = MouseGetPos()
  53.  
  54.     If @error Then ;will be non-zero if error
  55.         MsgBox($MB_TOPMOST, "", "Open your email first, then rerun script")
  56.         ;Exit
  57.     EndIf
  58.  
  59.     WinSetState($winHandle, "", @SW_MAXIMIZE)
  60.     WinActivate($winHandle)
  61.  
  62.     _ClipPutFile($fpath)
  63.  
  64.     If @error Then ; will be non-zero if it screwed up
  65.         MsgBox($MB_TOPMOST, "", "Error setting clipboard" & @CRLF & "Error: " & @error)
  66.         ;Exit
  67.     EndIf
  68.  
  69.     Sleep(1000)
  70.  
  71.     MouseClick("LEFT", $coordHomeTabBtn[0], $coordHomeTabBtn[1])
  72.     sleep(500)
  73.     MouseClick("LEFT", $coordNewEmailBtn[0], $coordNewEmailBtn[1])
  74.     Sleep(1000)
  75.     Send($toEmail)
  76.     Send("{TAB 3}") ; tab to subject
  77.     Send($subject)
  78.     Send("{TAB}")
  79.     Send("^a") ;SELECT ALL
  80.     Send("{BACKSPACE}") ;Clear the body text
  81.     Send("See file")
  82.     Send("^v") ;PASTE
  83.     MouseClick("LEFT", $coordSendBtn[0], $coordSendBtn[1])
  84.  
  85.  
  86. EndFunc   ;==>sendEmail
  87.  
  88. While 1
  89.     switch TrayGetMsg() ;detect which tray buttons are clicked onto
  90.         case $sendEmailTrayBtn
  91.             sendEmail()
  92.             showOriginWin()
  93.             resetMousePos()
  94.  
  95.         case $exitTrayBtn
  96.             Exit
  97.     EndSwitch
  98.  
  99.     $day = _DateDayOfWeek(@WDAY)
  100.  
  101.  
  102.         if $day == "Monday" or $day == "Tuesday" Or $day == "Wednesday" Or $day == "Thursday" then
  103.  
  104.             If _NowTime() = "09:00:00" or _NowTime() = "14:00:00" or _NowTime() = "16:45:00" Then
  105.                 MsgBox($MB_TOPMOST, "Mon-Thur", "Its time to send email of logbook")
  106.                 sendEmail()
  107.                 showOriginWin()
  108.                 resetMousePos()
  109.  
  110.                 if $emailNum == $emailMaxNum then
  111.                     $emailNum = 1
  112.                 else
  113.                     $emailNum +=1
  114.                 endif
  115.             EndIf
  116.  
  117.         elseif $day== "Friday" then
  118.             If _NowTime() = "09:00:00" or _NowTime() = "11:00:00" or _NowTime() = "13:00:00" Then
  119.                 MsgBox($MB_TOPMOST, "Friday", "Its time to send email of logbook")
  120.                 sendEmail()
  121.                 showOriginWin()
  122.                 resetMousePos()
  123.  
  124.                 if $emailNum == $emailMaxNum then
  125.                     $emailNum = 1
  126.                 else
  127.                     $emailNum +=1
  128.                 EndIf
  129.  
  130.             EndIf
  131.  
  132.     endif
  133.  
  134.     Sleep(100)
  135. WEnd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement