Jump to content
Sign in to follow this  
skyhigh

Problem about setting a specific time to run a program

Recommended Posts

skyhigh

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
ViciousXUSMC

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
skyhigh

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
skyhigh

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
ViciousXUSMC

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
skyhigh

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
ViciousXUSMC

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.

  • Like 1

Share this post


Link to post
Share on other sites
skyhigh

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  

  • Similar Content

    • Vikramjeet
      By Vikramjeet
      $oExcel = ObjCreate("Excel.Application") $oExcel.Visible = 0 #include <MsgBoxConstants.au3> #Include <File.au3> Global $arlines WinActivate("MyApplication") ;Activate My Application Local $hWnd = WinWaitActive("MyApplication", "", 5) ;Wait for My Application for 5 seconds $oExcel.Application.WorkBooks.Open("C:\Users\Charlie\Desktop\Data.xlsx") ;Open Excel file 'Data.xlsx' local $iCell = $oExcel.Application.Cells(31,1).Value ;Read the value from cell A31 $file = @ScriptDir & "\Capture.log" If $hWnd Then For $a = 1 to $iCell ;STEP 1 Send("G*L") Send($oExcel.Application.Cells($a,1).Value) Send("/XUSR") Sleep(1000) Send("{ENTER}") Sleep(2000) ;===> Once the script has sent the above formats to 'MyApplication, A log file (Capture.log) is generated. What do I add as a link so the script moves to ;the following steps _FileReadToArray ($file, $arlines) For $i = $arlines [0] To 1 Step - 1 ; Script starts reading the log file from bottom up If $arlines [$i] = "‡NOT VALID" Then ;===> If I find the word '‡NOT VALID', then I want the script to go to STEP 1 in loop Else ;====> Else I want the script to do the following steps Send("MB") ; Continue sending formats to 'MyApplication' Send("{ENTER}") Sleep(2000) $iNum = StringRegExp(FileRead($file), "(?sm).*^\h*(\d{1,3})", 1)[0] ; Read number at a certain location in Capture.log file ConsoleWrite($iNum & @CRLF) EndIf ;====> Use the captured $iNum in the loop below. What do I add to proceed to the following steps For $i = 1 To $iNum Send("SET"& $i &"/USR") Sleep(500) Send("{ENTER}") Sleep(1000) ;====> Go back to STEP 1 $oExcel.Application.Quit I am a beginner and need help with If, then, else jump to specific loop in the script. Can I please get help with my script where I have multiple loops. I need to link the steps and also break the sequence and jump to specific loop if a certain condition is found in one loop. 
    • Skeletor
      By Skeletor
      Hi Guys,
      Is it possible to get a variable on your For..Next loop? 
       
      Local $Lines1 = _FileCountLines(C:\temp\test.txt) Local $linesToCount2 = $Lines1 + 2 $var = Number($linesToCount2) For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = $var To $count Next ;Code does stuff here Next Somehow my code doesn't work even though I thought I could convert the variable to a Integer / Number.
      This code I posted above does not move to the next value.
      But the code below does... why is that?
      For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = 2 To $count Next ;Code does stuff here Next  
      Why is the For loop resetting itself?
      Is it because the program does not cache the variable and needs to keep on acquiring this variable each time?
      If so , how would you make this variable static?

       
    • milkmoron
      By milkmoron
      Hi is there a move next function or a way to loop so that the next item in a record is selected? I'm not sure where to start looking in order to find them. I want to click a text link and then do my macros, which I'm already finished with and then make it move to the next record. This is on a web browser it looks like this. The link is a date. I believe the page uses javascript Theres also a button for the bottom and I want it to do a whole date range 1/1/2016 - 7/1/2018

    • MrCheese
      By MrCheese
      hi all,
      Dumb question, but say I have a loop:
      dim $i Do     sleep(1000)          if $i = ; how do i do a function that enters this IF statement every 10 loops?         ; do stuff every 10     EndIf      Until $i = 100  
      - what commands in the if statement do I need to use to make it pass, and on every 10th loop, it enters the if statement. ?
       
      Thanks
    • MrCheese
×