Jump to content

Little help with first script


Recommended Posts

If you don't use the Int function, you'll get all of the numbers after the decimal point, this way makes the display cleaner.

So I'm using your latest edition of the script and I'm thinking about making a few changes.

Global $Timer = TimerInit()
Global $Timer2 = TimerInit()
Global $Delay = 1, $Delay2 = 1
While 1
    While @HOUR >= 8 And @HOUR < 17 ; easier to code it this way
        If TimerDiff($Timer) >= $Delay Then; Wait 30 minutes before running it again
            WinActivate("Warehose Menu Options")
            ControlClick("Warehose Menu Options", "", "[CLASS:TBitBtn; INSTANCE:7]")
            WinWaitActive("New Warehouse Orders")
            ControlClick("New Warehouse Orders", "", "[CLASS:TBitBtn; TEXT:&Print All; INSTANCE:1]")
            $Timer = TimerInit()
            $Delay = 1800000
        EndIf
        Sleep(100)
        If TimerDiff($Timer2) >= $Delay2 Then ; Only updates the time on the tool tip aprrox. once a minute
            Global $Minutes = 30 - Int(TimerDiff($Timer) / 60000)
            TraySetToolTip("Time Until Next Run: " & $Minutes)
            $Timer2 = TimerInit()
            $Delay2 = 61000
        EndIf
    WEnd
    TraySetToolTip("Script is sleeping until 8AM")
    $Delay = 1
    $Delay2 = 1
    Sleep(100)
WEnd

After the line ControlClick("New Warehouse Orders", "", "[CLASS:TBitBtn; TEXT:&Print All; INSTANCE:1]")

I want it to do one thing "if" a window titled "Printing" comes up, if after 30 seconds it does not, I want it to do something else. In either case, I need it to go back to it's 30 minute count down. How would I go about this?

Link to comment
Share on other sites

Alright, using the script example I found I think I've implemented sending a text to myself if there's a new request. Could someone check this for me?

#include "SMS.au3" ; Test

$server = "smtp.gmail.com" ; Test
$email = "xxxxxxxxxx"; Test
$username = "xxxxxxxxxxxx"; Test
$password = "xxxxxxxxxxxx"; Test
$port = 465; Test
$ssl = 1; Test

$number = xxxxxxxxxx; Test
$service = $ATT_WIRELESS; Test
$message = "New BoxStore Request"; Test

Global $Timer = TimerInit()
Global $Timer2 = TimerInit()
Global $Delay = 1, $Delay2 = 1
While 1
    While @HOUR >= 8 And @HOUR < 17 ; easier to code it this way
        If TimerDiff($Timer) >= $Delay Then; Wait 30 minutes before running it again
            WinActivate("Warehose Menu Options")
            ControlClick("Warehose Menu Options", "", "[CLASS:TBitBtn; INSTANCE:7]")
            WinWaitActive("New Warehouse Orders")
            ControlClick("New Warehouse Orders", "", "[CLASS:TBitBtn; TEXT:&Print All; INSTANCE:1]")
        If WinExists("Printing...") Then ; Test, delete before compile
                $sms = _SMS_Start($server,$email,$username,$password,$port,$ssl) _SMS_Send($sms,$number,$service,$message ;test
        Else
            $Timer = TimerInit()
            $Delay = 1800000
        EndIf
        Sleep(100)
        If TimerDiff($Timer2) >= $Delay2 Then ; Only updates the time on the tool tip aprrox. once a minute
            Global $Minutes = 30 - Int(TimerDiff($Timer) / 60000)
            TraySetToolTip("Time Until Next Run: " & $Minutes)
            $Timer2 = TimerInit()
            $Delay2 = 61000
        EndIf
    WEnd
    TraySetToolTip("Script is sleeping until 8AM")
    $Delay = 1
    $Delay2 = 1
    Sleep(100)
WEnd

What I want it to do is after it hits the Print All button, wait a few seconds to see if a window titled "Printing..." comes up, if it does, send me a text message then continue it's loop for the next 30min. If it doesn't, I want it to just continue it's loop.

Link to comment
Share on other sites

Ok, well I did a little editing on stuff I noticed I missed (I'm not very good at this yet).

However, it doesn't seem to be working. When the "Printing..." window appears, I get an error. I'm pretty sure the error comes from me not using the functions right. Would someone mind checking this for me?

#include "SMS.au3" ; Test

$server = "smtp.gmail.com" ; Test
$email = "zamphire@gmail.com"; Test
$username = "zamphire@gmail.com"; Test
$password = "xxxxxxxxxx"; Test
$port = 465; Test
$ssl = 1; Test

$number = xxxxxxxxx; Test
$service = $ATT_WIRELESS; Test
$message = "New BoxStore Request"; Test
$message2 = "Yep..."

Global $Timer = TimerInit()
Global $Timer2 = TimerInit()
Global $Delay = 1, $Delay2 = 1
While 1
    While @HOUR >= 8 And @HOUR < 17 ; easier to code it this way
        If TimerDiff($Timer) >= $Delay Then; Wait 30 minutes before running it again
            WinActivate("Warehose Menu Options")
            ControlClick("Warehose Menu Options", "", "[CLASS:TBitBtn; INSTANCE:7]")
            WinWaitActive("New Warehouse Orders")
            ControlClick("New Warehouse Orders", "", "[CLASS:TBitBtn; TEXT:&Print All; INSTANCE:1]")
            Sleep(2000)
                If WinExists("Printing...") Then ; Test, delete before compile
                $sms = _SMS_Start($server,$email,$username,$password,$port,$ssl) 
                _SMS_Send($sms,$number,$service,$message ;test
                EndIf
            $Timer = TimerInit()
            $Delay = 1800000
        EndIf
        Sleep(100)
        If TimerDiff($Timer2) >= $Delay2 Then ; Only updates the time on the tool tip aprrox. once a minute
            Global $Minutes = 30 - Int(TimerDiff($Timer) / 60000)
            TraySetToolTip("Time Until Next Run: " & $Minutes)
            $Timer2 = TimerInit()
            $Delay2 = 61000
        EndIf
    WEnd
    TraySetToolTip("Script is sleeping until 8AM")
    $Delay = 1
    $Delay2 = 1
    Sleep(100)
WEnd

In case it helps the error code I get is this "Error: Error parsing function call."

Edited by Zamphire
Link to comment
Share on other sites

You missed ) at end

_SMS_Send($sms,$number,$service,$message) ;test

You can run Au3Check by Ctrl+F5 in Scite - it will tell you where exactly and why is error in your script.

Alright, fixed that. Ran the CTRL+F5 and returned 0 errors. So I ran the script, and it works, but I didn't get a text message like I should have. How can I see if it tried to send one? That way I know if it's something I've done with implementation or settings, or if the UDF just doesn't work?

Here's the code just to check

#include "SMS.au3" ; Test

$server = "smtp.gmail.com" ; Test
$email = "zamphire@gmail.com"; Test
$username = "zamphire@gmail.com"; Test
$password = "xxxxxxxxx"; Test
$port = 465; Test
$ssl = 1; Test

$number = xxxxxxxxxxx; Test
$service = $ATT_WIRELESS; Test
$message = "New BoxStore Request"; Test
$message2 = "Yep..."

Global $Timer = TimerInit()
Global $Timer2 = TimerInit()
Global $Delay = 1, $Delay2 = 1
While 1
    While @HOUR >= 8 And @HOUR < 17 ; easier to code it this way
        If TimerDiff($Timer) >= $Delay Then; Wait 30 minutes before running it again
            WinActivate("Warehose Menu Options")
            ControlClick("Warehose Menu Options", "", "[CLASS:TBitBtn; INSTANCE:7]")
            WinWaitActive("New Warehouse Orders")
            ControlClick("New Warehouse Orders", "", "[CLASS:TBitBtn; TEXT:&Print All; INSTANCE:1]")
            Sleep(2000)
                If WinExists("Printing...") Then ; Test, delete before compile
                $sms = _SMS_Start($server,$email,$username,$password,$port,$ssl) 
                _SMS_Send($sms,$number,$service,$message) ;test
                EndIf
            $Timer = TimerInit()
            $Delay = 1800000
        EndIf
        Sleep(100)
        If TimerDiff($Timer2) >= $Delay2 Then ; Only updates the time on the tool tip aprrox. once a minute
            Global $Minutes = 30 - Int(TimerDiff($Timer) / 60000)
            TraySetToolTip("Time Until Next Run: " & $Minutes)
            $Timer2 = TimerInit()
            $Delay2 = 61000
        EndIf
    WEnd
    TraySetToolTip("Script is sleeping until 8AM")
    $Delay = 1
    $Delay2 = 1
    Sleep(100)
WEnd
Edited by Zamphire
Link to comment
Share on other sites

I replaced the

$sms = _SMS_Start($server,$email,$username,$password,$port,$ssl) 
                _SMS_Send($sms,$number,$service,$message) ;test
portion of the script with a MsgBox and the msgbox worked, so it's something I'm doing with implementation. I've done some searching on the forums to try to find out what I did wrong but can't seem to find it.

Can anyone tell me what I've done wrong?

Link to comment
Share on other sites

You may want to try and broaden your IF WinExists("Printing...") to include the title and text.

Printing is the title of the window, and there's no text in it.

However, I don't think that's the problem. Like I said, I put a _MsgBox right after the IF WinExists("Printing...") and it worked, so I'm pretty sure it's just how I'm putting the sms script in to my script.

Link to comment
Share on other sites

It looks like it's set up correctly. One question though, have you enabled POP access in Gmail for your account? If you haven't set up your account for POP access I don't think this will work.

EDIT: Another thing I thought of, you should put some error checks in after the $sms = line to make sure that it's returning an array and not erroring. Something like this:

$sms = _SMS_Start($server,$email,$username,$password,$port,$ssl) 
     ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $SMS = ' & $SMS & @crlf & '>Error code: ' & @error & @crlf) ; use this to see if there's an error message in @error and whether $sms returns a 0
     _ArrayDisplay($sms) ; If _ArrayDisplay doesn't pop up at this point, you have an error
     _SMS_Send($sms,$number,$service,$message) ;test

If the _SMS_Start returns ok, then you can error check the return from _SMS_Send the same way to see if there's an error at that point.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...