Sign in to follow this  
Followers 0
skyhigh

Problem about setting a specific time to run a program

8 posts in this topic

I am working at a script (thanks @Chimp for the help on my previous thread) operating on Firefox, based on two time-set loops that are doing the same operations with some differences.
Now I need to execute a local video at a determinated hour (between 12 and 4).  
My question is

What is the best way to determine a precise hour (hh:mm)? I tried

While @Hour >= 12 & @MIN >= 00 And @HOUR <= 14 & @MIN < 30

But the loop is being ignored, although in the moment I use only @Min for my tests everything works fine.

This is the essential - and working - structure of the present script:

#include <ff.au3>
_FFStart()
While @MIN >= 00 And @MIN < 30  ; 1st Firefox loop

    Firefox url loop (contains functions and if conditions)

WEnd

;Open a new tab and runs a local video;

While @MIN >= 32 And @MIN <= 59 ; 2nd Firefox loop

    Firefox url loop (contains functions and if conditions)

WEnd

Thanks in advance

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The reason the statement is not working is because your using "&" instead of "And" they have totally different functions :)

As for the code block your first loop will run from 0 to 30 min and then exit the loop,

The second loop starts at 32 to 59 minutes, with just the code posted if those loops are not inside of another larger loop I do not see how the second loop even starts because the first would exit at 30 minutes and then the code would continue bypassing the second loop entirely. 

A good way to fix that would be just one loop with If statements, also the code could run continually this way and never need to be restarted.

While 1
Sleep(10) 
If @Min >= 00 AND @Min < 30 Then
 ;Function
ElseIf @Min >= 32 AND @Min <=59
 ;Function
EndIf
WEnd

Also you can try assigning the macros to a variable so you do not have to keep reusing the macro and could even do a crude hour:min feature like this.

While 1
    Sleep(10)
    $iTime = Number(@Hour & @Min)
    If $iTime >= 1650 AND $iTime <= 1700 Then
       MsgBox(0, "", "It's between 4:50 and 5:00 !")
    EndIf
WEnd

 

Edited by ViciousXUSMC

Share this post


Link to post
Share on other sites

The reason the statement is not working is because your using "&" instead of "And" they have totally different functions :)

As for the code block your first loop will run from 0 to 30 min and then exit the loop,

The second loop starts at 32 to 59 minutes, with just the code posted if those loops are not inside of another larger loop I do not see how the second loop even starts because the first would exit at 30 minutes and then the code would continue bypassing the second loop entirely. 

A good way to fix that would be just one loop with If statements, also the code could run continually this way and never need to be restarted.

While 1
Sleep(10) 
If @Min >= 00 AND @Min < 30 Then
 ;Function
ElseIf @Min >= 32 AND @Min <=59
 ;Function
EndIf
WEnd

Also you can try assigning the macros to a variable so you do not have to keep reusing the macro and could even do a crude hour:min feature like this.

While 1
    Sleep(10)
    $iTime = Number(@Hour & @Min)
    If $iTime >= 1650 AND $iTime <= 1700 Then
       MsgBox(0, "", "It's between 4:50 and 5:00 !")
    EndIf
WEnd

Hello world!

Sorry, I had not the occasion to post due to some issues, but I worked on your idea @ViciousXUSMC

I think that the easiest way to write more loops is to write more scripts, each one activating at a certain $iTime, right?

The problem is, if I use an infine loop (While 1) I can't even close FF at the end of the loop.

So I need to stop the loop, how?

Should I write a secondary script that stops the primary script?

Share this post


Link to post
Share on other sites

The reason the statement is not working is because your using "&" instead of "And" they have totally different functions :)

As for the code block your first loop will run from 0 to 30 min and then exit the loop,

The second loop starts at 32 to 59 minutes, with just the code posted if those loops are not inside of another larger loop I do not see how the second loop even starts because the first would exit at 30 minutes and then the code would continue bypassing the second loop entirely. 

A good way to fix that would be just one loop with If statements, also the code could run continually this way and never need to be restarted.

While 1
Sleep(10) 
If @Min >= 00 AND @Min < 30 Then
 ;Function
ElseIf @Min >= 32 AND @Min <=59
 ;Function
EndIf
WEnd

Also you can try assigning the macros to a variable so you do not have to keep reusing the macro and could even do a crude hour:min feature like this.

While 1
    Sleep(10)
    $iTime = Number(@Hour & @Min)
    If $iTime >= 1650 AND $iTime <= 1700 Then
       MsgBox(0, "", "It's between 4:50 and 5:00 !")
    EndIf
WEnd

Hello world!

Sorry, I had not the occasion to post due to some issues, but I worked on your idea @ViciousXUSMC

I think that the easiest way to write more loops is to write more scripts, each one activating at a certain $iTime, right?

The problem is, if I use an infine loop (While 1) I can't even close FF at the end of the loop.

So I need to stop the loop, how?

Should I write a secondary script that stops the primary script?

Share this post


Link to post
Share on other sites

Would be hard to help without knowing how your function works.

Sounds to me instead of needing to run between (start time) and ending at (stop time) you just need a (start time) only.

So just modify like so:

While 1
    Sleep(10)
    $iTime = Number(@Hour & @Min)
    If $iTime = 1650 Then MsgBox(0, "", "Function Started @ 4:50PM")
    If $iTimer = 1850 Then MsgBox(0, "", "Function Started @ 6:50PM")
WEnd

 

If your going to have a bunch of different start times that is a good chance to use Switch/EndSwitch instead of If/EndIf statements.

Share this post


Link to post
Share on other sites

Would be hard to help without knowing how your function works.

Sounds to me instead of needing to run between (start time) and ending at (stop time) you just need a (start time) only.

So just modify like so:

While 1
    Sleep(10)
    $iTime = Number(@Hour & @Min)
    If $iTime = 1650 Then MsgBox(0, "", "Function Started @ 4:50PM")
    If $iTimer = 1850 Then MsgBox(0, "", "Function Started @ 6:50PM")
WEnd

 

If your going to have a bunch of different start times that is a good chance to use Switch/EndSwitch instead of If/EndIf statements.

I am sorry, I should have explained myself better from the beginning. I'll try to do it now.
Here the operations I need

1)To run firefox at a certain hour (HH:MM),
2)To open a random url taken from a list, let it open then close it
3)To keep doing it until a determined hour (HH:MM)
4)To change the list where the urls are taken from
5)Repeat 2) until is time for the script to stop itself (HH:MM).
6)To execute a local video at given times (HH:MM, HH:MM, etc)

Notes (number related)
1)Thanks to the FF libraries I can easily operate in Firefox, so no problem there.
2)To open the urls randomly I wrote this code (example of the code structure)

Global $aURLS[6]
$aURLS[1] = "www.youtube.com" 
$aURLS[2] = "www.yahoo.com"
$aURLS[3] = "www.vimeo.com"
$aURLS[4] = "www.dailymotion.com"
$aURLS[5] = "www.twitch.tv"

$x = Random(1, 5, 1)

_FFTabAdd($aURLS[$x], True, True)
WinWaitActive("Tab",0,10)

Sleep(5 * 1000) 

_FFTabClose("0", "index")
Sleep(5000)

    Select
    Case $x <= 2
    MouseClick(x,y)
    Sleep(15 * 1000) 
    MouseClick(x,y)

    Case $x >= 3
    MouseWheel("down", 1)                   
    Sleep(2000)
    MouseClick(x,y) 
    Sleep(15 * 1000)
    MouseClick(x,y)

EndSelect


So, that is the essential code I need to loop. The case select is necessary to maximize the video window in different websites.
3)I don't care if the script is only one or I have to divide it. I just need it to work correctly.
4)There are two (al least) lists of urls. This is a vital part of the script
6)This is vital too, so I am taking into consideration to write 3 scripts instead of only one. It looks easier, do you agree?

 

Share this post


Link to post
Share on other sites

I'll look at this more later, but I can tell you that running separate loops like you posted in your example should behave no different than the While loop I posted so the issue that is happening must have something to do with your code.

If you really want to do this in a professional manner you should look at the IUIAutomation thread where you can click/full screen without using MouseClick() so that it will always work no matter the resolution, and I think FireFox UDF has methods to detect when a page has loaded so you can get rid of the excessive Sleep() you have for page loading.

1 person likes this

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I found out my mistake: ""

Daaaaamn quotes!

$iTime = Number(@Hour & @Min)
For $iTime = "1640" To "1642"

This "timer" appears to be workimg well! EDIT: well, seems it does not work if I don't include a piece of code I found surfing the net.

I checked the IUIAutomation thread. It looks very useful and I thank you for pointing it out to me, but I have the impression it requires to be more skilled than the level I am presently.

You are right, it exists the _FFLoadWait function, better than Sleep, thanks for the hint

I'll continue my work on the script, thank you for you help!

Edited by skyhigh

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  
Followers 0

  • Similar Content

    • MrCheese
    • JohnNash
      By JohnNash
      I've seen some weird behavior in my code (I log almost everything).

       
         While 1       $WaitingTime = TimerDiff($wtTimer)       sleep(300)       $Data = TCPRecv($MainSocket, $MaxLength)       _FileWriteLog($LogFolder&"info.log", "Wait for answer that Server is ready for step 21")                            If $Data = "ByeBye" Then                                        _FileWriteLog($LogFolder&"info.log", "Server tells me to shutdown")                                        Terminate()                  ElseIf $Data = "Step 20 Finished on Server" Then                                         _FileWriteLog($LogFolder&"info.log", "Server answers it is ready for step 21")                                         ExitLoop                ElseIf $WaitingTime>4000 Then                                          _FileWriteLog($LogFolder&"info.log", "No Answer, we still continue" &$Data)                                          ExitLoop             EndIf    WEnd    _FileWriteLog($LogFolder&"info.log", "Left the WhileLoop")  
       
      And my logs show this:
       

      2016-10-24 00:52:39 : Wait for answer that Server is ready for step 21

      2016-10-24 00:52:39 : (Logline from completely different loop)
      2016-10-24 00:52:39 : (Logline from completely different loop)
      2016-10-24 00:52:39 : (Logline from completely different loop)
      2016-10-24 00:52:39 : (Logline from completely different loop)

      2016-10-24 00:52:40 : Wait for answer that Server is ready for step 21
      2016-10-24 00:52:40 : Server answers it is ready for step 21
       
      How can this happen? (If there was a "Left the Whileloop" log in between I could imagine it could happen... but now?
      I thought AutoIT was singlethreaded...
       
       
       
       
       
    • Miliardsto
      By Miliardsto
      My function still making spells and ignoring if statement
      -snip-
      And this function returns true and i see spell is entering
    • ces1a
      By ces1a
      I recently upgraded my laptop to one with Windows 10 and higher screen resolution.  In the process I found that some of my scripts did not work right when using Autoit's @DesktopWidth and @DesktopHeight macros.  Insteat of 1920 x 1080 resolution Autoit detects 1536 x 864.  Thus, GUIs designed to appear near the right edge of the screen  displayed closer to the horizontal middle of the screen.  I assume others may have the same problem.
      A search on this forum and Microsoft Script Center helped me to write the following script that gets the true screen width and height from WMI.
      MsgBox(0, '', _GetMonitorInfo())
      Func _GetMonitorInfo()
          Local $oWMI, $Listing, $sWidth = 0, $sHeight = 0
          $oWMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
          If IsObj($oWMI) Then
              $Listing = $oWMI.ExecQuery("SELECT * FROM Win32_DesktopMonitor")
              If IsObj($Listing) Then
                  For $oItem In $Listing
                      $sHeight = $oItem.ScreenHeight
                      $sWidth = $oItem.ScreenWidth
                  Next
              EndIf
          EndIf
          Return "Width: " & $sWidth & @CRLF & "Height: " & $sHeight
      EndFunc ;_GetMonitorInfo

      Hopefully it will benefit others.  I for sure am very happy with all the samples I been able to find here in the past.
    • Razormaul
      By Razormaul
      This is a repost, since the thread was deleted due to database issues. - https://www.autoitscript.com/forum/topic/173518-thread-deleted/
       
      Hello fellow geeks
      I am making a small program for work, a tool with shortcuts and host monitoring.
      The program has several tab and  I need help with the tab called "Servers/Hosts"
      The tab reads hostnames or ip adresses from an ini file and writes them to a listview. You can add or remove hosts, ping, connect with mstsc and delete the whole list. Now...
      Im checking for ip adresses on start of the program, or with a refresh button - so far so good.. It´s working.
      I also have a function to check if a host is online and write it to the listview, but i cant make it work (im not good enough yet) - (ALMOST SOLVED -  Writing a dummyhost e.g. "test" as hostname, gets the status "Online" - im currently working on that )
      This check needs to run every 10 seconds or so, among with the check for ip adresses. But again, (im not good enough yet) - (SOLVED USING AdlibRegister)
      I´ve tried to put the functions in a loop in different places in the script. They either "block" the script or hide it.
      If i can get the loop to work, there is no need for a refresh button. and i want to put the foldercheck in the VIKING tab in a similar loop, displaying a warning instead of having to click a button. (but thats a different question)
      I hope one of you briliant minds can help me along the way:) Thank you for your time.
      Tobias
       
       
      IT-Tools.V13.au3
      Servers.ini