Zamphire Posted May 27, 2011 Share Posted May 27, 2011 I'm rather new to AutoIt scripting. I'm trying to write a script that will automate a task we do at work every 30 minutes. I've got the automation part correct, it works. Now I'm trying to make it continuously loop every 30min until 5PM when it closes. Will this work? #include <Date.au3> $time = _NowTime() While 1 endif _NowTime()="5:00PM" else 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(1800000) WEnd Link to comment Share on other sites More sharing options...
BrewManNH Posted May 27, 2011 Share Posted May 27, 2011 (edited) You'd need to do something like this:; #include <Date.au3> $Timer = TimerInit() While Not @Hour >= 17 ; easier to code it this way If TimerDiff($Timer) >= 1800000 ; 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() Endif WEndYou had no If statement in the loop so it wouldn't run even if you tried it, you just have Endif and Else statements, and they're in the wrong sequence. If you want it to run the first time through the loop, then change the line $Timer = TimerInit() that's located before the While to this $Timer = 1800000. Edited May 27, 2011 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 GudeHow 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 More sharing options...
November Posted May 27, 2011 Share Posted May 27, 2011 (edited) Hi there,AdlibRegister("doit", 1800000) While 1 Sleep(100) WEnd func doit() 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]") EndFunc* I missed the 5:00PM condition, but here's another way to start!Cheers Edited May 27, 2011 by November Old Scriptology Visual Ping 1.8 - Mass Ping Program with export to txt delimited. Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code. Desktop 2 RGB - Pick a color in the desktop and get the RGB code. ShootIT 1.0 - Screen Capture full and partial screen [font="'Arial Black';"]Remember Remember The Fifth of November.[/font] Link to comment Share on other sites More sharing options...
Zamphire Posted May 27, 2011 Author Share Posted May 27, 2011 (edited) You'd need to do something like this: ; #include <Date.au3> $Timer = TimerInit() While Not @Hour >= 17 ; easier to code it this way If TimerDiff($Timer) >= 1800000 ; 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() Endif WEnd You had no If statement in the loop so it wouldn't run even if you tried it, you just have Endif and Else statements, and they're in the wrong sequence. If you want it to run the first time through the loop, then change the line $Timer = TimerInit() that's located before the While to this $Timer = 1800000. Alright, compiled this script #include <Date.au3> $time = _NowTime() $Timer = 1800000() While Not _NowTime()="5:00PM" If TimerDiff($Timer) >= 1800000 ; 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() Endif I do need it to run the first time through. I'll give it a try and hope it works. Thanks! That brings up another question, if I compile it to move it to a computer that doesn't have AutoIt installed, are the included functions going to be in the .exe file? Edited May 27, 2011 by Zamphire Link to comment Share on other sites More sharing options...
BrewManNH Posted May 27, 2011 Share Posted May 27, 2011 (edited) You need to remove the () after the 1800000, you will get an error. Also, I rewrote the script example above to make it easier to use. Edited May 27, 2011 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 GudeHow 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 More sharing options...
BrewManNH Posted May 27, 2011 Share Posted May 27, 2011 That brings up another question, if I compile it to move it to a computer that doesn't have AutoIt installed, are the included functions going to be in the .exe file?When compiled, it adds the includes to the compiled script. 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 GudeHow 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 More sharing options...
Zamphire Posted May 27, 2011 Author Share Posted May 27, 2011 Alright, tried to run it and it returns an error If TimerDiff($Timer) >= 1800000 Error: "If" statements must have a "Then" keyword Link to comment Share on other sites More sharing options...
November Posted May 27, 2011 Share Posted May 27, 2011 Another way AdlibRegister("doit", 1800000) While 1 $time = @HOUR & @MIN if $time >= 1700 Then Exit Else Sleep(100) EndIf WEnd func doit() 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]") EndFunc Cheers Old Scriptology Visual Ping 1.8 - Mass Ping Program with export to txt delimited. Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code. Desktop 2 RGB - Pick a color in the desktop and get the RGB code. ShootIT 1.0 - Screen Capture full and partial screen [font="'Arial Black';"]Remember Remember The Fifth of November.[/font] Link to comment Share on other sites More sharing options...
BrewManNH Posted May 27, 2011 Share Posted May 27, 2011 Alright, tried to run it and it returns an error If TimerDiff($Timer) >= 1800000 Error: "If" statements must have a "Then" keyword Meathead move on my part, please add the keyword Then after the 1800000. sorry about that. 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 GudeHow 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 More sharing options...
Zamphire Posted May 27, 2011 Author Share Posted May 27, 2011 Meathead move on my part, please add the keyword Then after the 1800000. sorry about that. Alright, added the then. Then it came with an error saying you need Wend after every while statement, so I added it. Ran the script, and it instantly goes away without doing anything. #include <Date.au3> $time = _NowTime() $Timer = 1800000 While Not _NowTime()="5:00PM" If TimerDiff($Timer) >= 1800000 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() Endif wend Link to comment Share on other sites More sharing options...
BrewManNH Posted May 27, 2011 Share Posted May 27, 2011 I have rewritten the script in the second post and now I've rewritten it again to make it less likely to not fail. Please use this code and let me know if it works for you. Do not use the code that you are currently using as I don't think the _NowTime returns the time as you want it to. $Timer = 1800000 While @HOUR < 17 ; easier to code it this way If TimerDiff($Timer) >= 1800000 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() EndIf Sleep(100) WEnd I actually was able to test the timing of this code. I wasn't able to do that to the previous code due to not being at my usual computer. 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 GudeHow 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 More sharing options...
Zamphire Posted May 27, 2011 Author Share Posted May 27, 2011 I have rewritten the script in the second post and now I've rewritten it again to make it less likely to not fail. Please use this code and let me know if it works for you. Do not use the code that you are currently using as I don't think the _NowTime returns the time as you want it to. $Timer = 1800000 While @HOUR < 17 ; easier to code it this way If TimerDiff($Timer) >= 1800000 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() EndIf Sleep(100) WEnd I actually was able to test the timing of this code. I wasn't able to do that to the previous code due to not being at my usual computer. Thanks! Compiled it and ran it, worked great the first time. I'll let you know in 30 minutes if it runs like it's supposed to!! Just a question, this isn't necessary but it would be nice. Is it possible to make AutoIt send a text message to my phone? Link to comment Share on other sites More sharing options...
Zamphire Posted May 27, 2011 Author Share Posted May 27, 2011 Seems to be working great! Thanks. Link to comment Share on other sites More sharing options...
BrewManNH Posted May 27, 2011 Share Posted May 27, 2011 I'm glad it's finally working correctly for you. You can probably use one of the SMS text programs that have been posted here to send a text message to your phone, or even email because some of the providers allow email to be sent to a phone as an SMS text message. 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 GudeHow 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 More sharing options...
Zamphire Posted May 27, 2011 Author Share Posted May 27, 2011 I'm glad it's finally working correctly for you. You can probably use one of the SMS text programs that have been posted here to send a text message to your phone, or even email because some of the providers allow email to be sent to a phone as an SMS text message.Would it be possible to have it so that if you mouse over the exe file in the system tray it will display time remaining until next loop? Link to comment Share on other sites More sharing options...
BrewManNH Posted May 27, 2011 Share Posted May 27, 2011 (edited) Would it be possible to have it so that if you mouse over the exe file in the system tray it will display time remaining until next loop? TraySetToolTip should do the trick, just have it update the tooltip as it loops around the While loop. Something like this: $Timer = 1800000 $Timer2 = 61000 While @HOUR < 17 ; easier to code it this way If TimerDiff($Timer) >= 1800000 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() EndIf Sleep(100) If TimerDiff($Timer2) >= 61000 Then ; Only updates the time on the tool tip aprrox. once a minute Global $Minutes = 30 - Int(TimerDiff($Timer)/60000) TraySetToolTip($minutes & " minutes left until next run") $Timer2 = TimerInit() EndIf WEnd This will display a message telling how many minutes remaining until it runs again if you hover over the tray icon. The icon will have to be showing for it to work correctly according to the help file. Edited May 27, 2011 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 GudeHow 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 More sharing options...
Zamphire Posted May 27, 2011 Author Share Posted May 27, 2011 You are a genius my sir. Thank you very much. Link to comment Share on other sites More sharing options...
BrewManNH Posted May 27, 2011 Share Posted May 27, 2011 I have altered the script again for a different approach. This version will continuously run as long as the computer is logged in (and of course on ), but only between certain hours. This version will only run between 8 AM and 5 PM, so in case you leave the computer running all of the time, and don't feel like restarting the program every day you can use this to have it running whenever you need it without havig to remember to start it. 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($Minutes & " minutes left until next run") $Timer2 = TimerInit() $Delay2 = 61000 EndIf WEnd TraySetToolTip("Script is sleeping until 8AM") $Delay = 1 $Delay2 = 1 Sleep(100) WEnd You may notice that i've changed the timing loops a bit. I wasn't too sure if it would always run the way it was written before, I miscoded the time delay checks, so I redid them. 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 GudeHow 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 More sharing options...
Zamphire Posted May 27, 2011 Author Share Posted May 27, 2011 (edited) I have a question, trying to follow what you did here so I can learn how it worksThis line:Global $Minutes = 30 - Int(TimerDiff($Timer)/60000)Why did you use 30 - Int(TimerDiff($Timer)/60000), wouldn't 30 - ($Timer/60000) have done the same thing?Oh, I see I see. You called the function TimerDiff to find the time difference since the last time it was ran, then divided by 60,000 to convert it into second. Gotcha. Edited May 27, 2011 by Zamphire Link to comment Share on other sites More sharing options...
BrewManNH Posted May 27, 2011 Share Posted May 27, 2011 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. 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 GudeHow 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now