PennyDreadful

How to run script in specific times by itself

7 posts in this topic

I have this script I would like to know how can I run it in specific times in each day of the week for example on sunday runs at 6 am and 5 pm and each other day has specific times. And stay running all the week days no need to launch it each time.

Anyone can help with it I tried many ways. 

; ----------------------------------------------------------------------------

; Script Start - Add your code below here
#NoTrayIcon
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <UpdownConstants.au3>
#include <IE.au3>
#include <date.au3>
#include <string.au3>
#include <ScreenCapture.au3>

;Your code

HotKeySet("{ESC}", "Terminate")
Func terminate()
    Exit 0
EndFunc

Local $ShellObj = ObjCreate("Shell.Application")
$ShellObj.ToggleDesktop()

ShellExecute ("http://www.pme.gov.sa/Ar/alert/Pages/default.aspx")

sleep (5000)


Example1()

Func Example1()
    Local $hBmp

    ; Capture full screen
    $hBmp = _ScreenCapture_Capture("")

    ; Save bitmap to file
    _ScreenCapture_SaveImage(@MyDocumentsDir & "\Weather Alerts.jpg", $hBmp)

    ShellExecute(@MyDocumentsDir & "\Weather Alerts.jpg")
EndFunc   ;==>Example

Sleep (500)

WinClose ( WinGetTitle("[ACTIVE]"))
ProcessClose("iexplore.exe")

 

Share this post


Link to post
Share on other sites



2 hours ago, PennyDreadful said:

Anyone can help with it I tried many ways.

Schedule a Task

Share this post


Link to post
Share on other sites

i tried that . i want prevent it from running during specific times using script not using Schedule a Task

Share this post


Link to post
Share on other sites

@PennyDreadful, welcome to AutoIt and to the forum.

regardless if your code and configuration are the optimal for the task at hand, AutoIt provides you with time macros, so you can easily tell what the current time is. look at the help file: AutoIt \ Language Reference \  Macros. notice @YEAR, @MON, @MDAY, @HOUR, @MIN, @SEC and others. a simple If..Then check at convenient intervals should do the trick.

Share this post


Link to post
Share on other sites

@orbs  I want to use the if...then command to compare the system time to a specified time so that the program can't run before or after that time. how can I do this using the macros you specified? Also how to define a macro to specific time? 

Any help will be appreciated. Thanks !!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

here is a simple example:

While True
    If @WDAY = 1 And (@HOUR = '06' Or @HOUR = '17') And @MIN = '00' Then ; start on Sunday at 6:00 and 17:00
        ; scheduled action here
    EndIf
    Sleep(1000 * 60)
WEnd

i trust the condition line is self-explanatory. what is important here is the Sleep() call. it is used for two purposes:

1) prevent your script from hogging the CPU while doing nothing

2) make sure the action does not run twice for the same scheduled time, in case it takes less than one minute to complete.

 

 

Edited by orbs

Share this post


Link to post
Share on other sites

@orbs yes this works for me using the while function . thanks a lot :thumbsup::thumbsup:

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