Jump to content

How to run script in specific times by itself


Recommended Posts

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")

 

Link to comment
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.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

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

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

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