Jump to content

time range


Bert
 Share

Recommended Posts

I'm looking for a way to have a script perform a task only when the time is between 07:00 and 17:00. The script would have a while statement so it would loop while running. Once the time is 17:00, the while statement would stop, and the script would exit.

I wrote some of the script, but I'm having trouble with the time part. I have no ide how to handle the time issue.

I came up with this script, but it doesn't work. Any help would be helpful

AutoItSetOption("WinTitleMatchMode", 2)

if winexist ("name of window") Then

$time = _DateTimeFormat( _NowCalc(),4)

if $time == 07:00 to 17:00

while

WinWaitActive ("name of window")

send("!A")

sleep(1500000)

Wend

else exit

EndIf

Endif

Link to comment
Share on other sites

I'm looking for a way to have a script perform a task only when the time is between 07:00 and 17:00. The script would have a while statement so it would loop while running. Once the time is 17:00, the while statement would stop, and the script would exit.

I wrote some of the script, but I'm having trouble with the time part. I have no ide how to handle the time issue.

I came up with this script, but it doesn't work. Any help would be helpful

AutoItSetOption("WinTitleMatchMode", 2)

if winexist ("name of window") Then

  $time = _DateTimeFormat( _NowCalc(),4)

      if $time == 07:00 to 17:00

        while

          WinWaitActive ("name of window")

          send("!A")

          sleep(1500000)

        Wend

      else exit

      EndIf

Endif

<{POST_SNAPBACK}>

I did something a little different in my script which checks for time.

If @Hour = 7 Then 
   MyFunction()
ElseIf @Hour = 17 Then
   EndFunction()
EndIf

I know this isn't quite writing your code for you, but it should point you in the right direction or at least give you some ideas.

Edit: Welcome to the forums!

Edited by SerialKiller
Link to comment
Share on other sites

maybe like this

#include<Date.au3>

AutoItSetOption("WinTitleMatchMode", 2)
if WinExists("") Then
$time = _DateTimeFormat( _NowCalc(),4) 

    while $time >= "07:00" And $time <= "17:00"
    ;WinWaitActive ("")
        MsgBox(0,"", $time)
        send("!A")
        sleep(10000)
        $time = _DateTimeFormat( _NowCalc(),4) 
    Wend
else 
    exit
EndIf

hope that helps

8)

NEWHeader1.png

Link to comment
Share on other sites

  • Developers

Happy to see you like the Date UDF's but in this case you can keep it real simple like:

while @HOUR >= 7 And @HOUR < 17
       ; ... whatever is needed here 
    Wend

:whistle:

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Happy to see you like the Date UDF's but in this case you can keep it real simple like:

while @HOUR >= 7 And @HOUR < 17
      ; ... whatever is needed here 
    Wend

:whistle:

<{POST_SNAPBACK}>

just a hobbyist following posters code...

but.. you missed an "="

While @HOUR >= 7 And @HOUR <= 17
    ; ... whatever is needed here 
Wend

8)

Edit... maybe not?

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

  • Developers

just a hobbyist following posters code...

but.. you missed an "="

Edit...  maybe not?

<{POST_SNAPBACK}>

Maybe not sounds right..

Think it needs to stop at 17:00 .....

:whistle:

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

got it working

I did this:

AutoItSetOption("WinTitleMatchMode", 2)

if WinExists("") Then

while @HOUR >= 7 And @HOUR < 17

WinSetState ( "", "", @SW_SHOW)

WinWaitActive ("Unicenter ServicePlus Service Desk")

send("!A")

sleep(1500000)

Wend

endif

I discovered a second problem. I need to window to become active before sending the command. I tried WinSetState, but it isn't working.

Link to comment
Share on other sites

  • Developers

I discovered a second problem. I need to window to become active before sending the command. I tried WinSetState, but it isn't working.

<{POST_SNAPBACK}>

WinSetState() doesn't change the Focus it just sets the state of the window.

You could also try the Control.... commands, because that can send info to controls in a Window without having the Focus....

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Got it!

;sets the title match to get only a substring in the window title

AutoItSetOption("WinTitleMatchMode", 2)

;looks to see if the window exist

if WinExists("Window name", "window text") Then

;Sets scope on when the while statement will run

while @HOUR >= 7 And @HOUR < 17

;sets the focus to the window in question

WinActivate ( "Window name" , "window text" )

;makes sure the window is active before sending command. I found if clicking just at that time, the keystroke might be sent to a different window.

WinWaitActive ("Window name", "window text" )

;send keystroke to refresh the window in question. In this case, a (Alt + A)

send("!A")

;The script pauses for 25 minutes before looping. To loop for 1 second, you would type sleep(1000)

sleep(1500000)

;End while statement

Wend

;End if statement

endif

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...