Jump to content
Sign in to follow this  
Bert

time range

Recommended Posts

Bert

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

Share this post


Link to post
Share on other sites
AutoChris

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

Share this post


Link to post
Share on other sites
Valuater

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

Share this post


Link to post
Share on other sites
Jos

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:


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Valuater

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

Share this post


Link to post
Share on other sites
Jos

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:


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Bert

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.

Share this post


Link to post
Share on other sites
Jos

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Bert

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

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  

×