Jump to content
Sign in to follow this  
SilverDeath

Need Help with a Script Im working on

Recommended Posts

I'm working on a script which will alert me via Audible alert or Cell Phone Text if a new Instant Messnager windows pops up, I intend to do this by PixelSearch and _INetSmtpMailCom.

Im having a few problems though, only one part of the script works, depending on which one comes first. If I switch the one that does sound to come before the one that does text, the sound works and vise versa. See below:

While 1
While $TOn = True
Do
$coord = PixelSearch( $CoordX, $CoordY, $CoordX, $CoordY, 0xAA150E, 20 )
If Not @error Then _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
Until Not @error
Sleep(3600000)
WEnd
WEnd

While 1
While $AOn = True
$coord = PixelSearch( $CoordX, $CoordY, $CoordX, $CoordY, 0xAA150E, 20 ) 
If Not @error Then Alert($coord, $AlarmSound)
WEnd
WEnd

Not quite sure what Im doing wrong but any help to point me in the right direction would be great. The Whole scipt and config file is below:

;##################################
; Include
;##################################
#Include<file.au3>

;##################################
; Audio Hotkey Startup
;##################################
HotKeySet("{F5}", "AStartStop")
$AOn = False

;##################################
; Text/Email Hotkey Startup
;##################################
HotKeySet("{F6}", "TStartStop")
$TOn = False

;##################################
; Variables
;##################################
Global $CellEmail = IniRead("Config.ini", "Text", "CellPhoneEmail", "NotFound")
Global $SmtpServer = "smtp.mail.yahoo.com"         
Global $FromName = "Instant Messanger Alarm"        
Global $FromAddress = "***********@yahoo.com" 
Global $ToAddress = $CellEmail
Global $Subject = "You have a message waiting for you"                  
Global $Body = "Please check your computer, you have a new message!"                              
Global $AttachFiles = ""                       
Global $CcAddress = ""       
Global $BccAddress = ""     
Global $Importance = "High"                  
Global $Username = "*******"                    
Global $Password = "*******"                  
Global $IPPort = 465  
Global $ssl = 1  
Global $CoordX = IniRead("Config.ini", "CordX", "x", "NotFound")
Global $CoordY = IniRead("Config.ini", "CordY", "y", "NotFound")
Global $AlarmSound = IniRead("Config.ini", "Alarm", "Alarm", "NotFound")


While 1
While $TOn = True
Do
$coord = PixelSearch( $CoordX, $CoordY, $CoordX, $CoordY, 0xAA150E, 20 )
If Not @error Then _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
Until Not @error
Sleep(3600000)
WEnd
WEnd

While 1
While $AOn = True
$coord = PixelSearch( $CoordX, $CoordY, $CoordX, $CoordY, 0xAA150E, 20 ) 
If Not @error Then Alert($coord, $AlarmSound)
WEnd
WEnd


;##################################
; Audio Hotkey Function
;##################################                          

Func AStartStop()
If $AOn = False Then
$AOn = True
MsgBox(0, "Instant Messanger Alarm", "Audible Alarm Enabled.")
Else
$AOn = False
MsgBox(0, "Instant Messanger Alarm", "Audible Alarm Disabled.")
EndIf
EndFunc

;##################################
; Text Hotkey Function
;##################################  
Func TStartStop()
If $TOn = False Then
$TOn = True
MsgBox(0, "Intant Messanger Alarm", "Text Message Alarm Enabled.")
Else
$TOn = False
MsgBox(0, "Intant Messanger Alarm", "Text Message Alarm Disabled.")
EndIf
EndFunc

;##################################
; Audible Alert Function
;################################## 

Func Alert($coord, $ColAlert = "Alert")
Local $temp, $File
$temp = StringReplace($ColAlert & " " & $ColAlert, " ", "+")
$File = StringRegExpReplace($ColAlert, "([ .,!])", "") 
If Not FileExists(@TempDir & "\" & $File & ".mp3") Then _
InetGet("http://translate.google.com/translate_tts?q=" & $temp, _
@TempDir & "\" & $File & ".mp3")
SoundPlay(@TempDir & "\" & $File & ".mp3", 1)
Return
EndFunc ;==>Alert

;##################################
; Text/Email Script
;##################################
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
$rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
If @error Then
    MsgBox(0, "Error sending message", "Error code:" & @error & "  Description:" & $rc)
EndIf

;##################################
; Text/Email Function
;##################################
Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
    Local $objEmail = ObjCreate("CDO.Message")
    $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
    $objEmail.To = $s_ToAddress
    Local $i_Error = 0
    Local $i_Error_desciption = ""
    If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
    If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
    $objEmail.Subject = $s_Subject
    If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then
        $objEmail.HTMLBody = $as_Body
    Else
        $objEmail.Textbody = $as_Body & @CRLF
    EndIf
    If $s_AttachFiles <> "" Then
        Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
        For $x = 1 To $S_Files2Attach[0]
            $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
;~          ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
            If FileExists($S_Files2Attach[$x]) Then
                ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
                $objEmail.AddAttachment($S_Files2Attach[$x])
            Else
                ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
                SetError(1)
                Return 0
            EndIf
        Next
    EndIf
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
    If Number($IPPort) = 0 then $IPPort = 25
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
    ;Authenticated SMTP
    If $s_Username <> "" Then
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
    EndIf
    If $ssl Then
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
    ;Update settings
    $objEmail.Configuration.Fields.Update
    ; Set email Importance
    Switch $s_Importance
        Case "High"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"
        Case "Normal"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"
        Case "Low"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"
    EndSwitch
    $objEmail.Fields.Update
    ; Sent the Message
    $objEmail.Send
    
    If @error Then
        SetError(2)
        Return $oMyRet[1]
    EndIf
    $objEmail=""
EndFunc  

;##################################
; Error Function
;##################################
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description, 3)
    ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)
    SetError(1); something to check for when this function returns
    Return
EndFunc

[CordX]
x=315

[CordY]
y=727

[Alarm]
Alarm=New IM!


[Text]
CellPhoneEmail=**********@yahoo.com

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...