Running a Python script on a schedule can be useful, either for scheduled data mining or updating of a dashboard on Google Sheets.
There are cloud solutions out there, but there's a simple GUI version of a scheduler for scripts on Windows that can be used.
The programme is included in most (if not all) Windows PCs and it's called the Task Scheduler.
Click on the Cortana or Search button beside the Start button if you're on Windows 10 and search for "Task Scheduler".
If you're on other versions of Windows, you can find the programme at Start Menu > All Programs > Accessories > System tools > Task Scheduler.
Once you open it, you should see a list of scheduled programmes. If not, just double-click on the "Task Scheduler Library" at the left sidebar.
You should be seeing this interface by now. (My tasks are pixelated for security reasons)
Click on the "Create Basic Task..." option on the right sidebar to start scheduling your task.
You'll be prompted to name your task and to provide it with a description. I advise you to give a name that separates it from all your current tasks that you saw on the list earlier. This will make it easier to find later.
Usually, I name my task with a "(_PYTHON)" identifier in front so it's easier to identify.
The description is optional. Use it if you have a need to remind yourself what was the task for again.
Click Next and you will see a prompt to set your schedule. Choose whichever option that suits your needs the best.
After you're done with selecting the schedule, click Next and select the first option on a very redundant section of this Wizard.
The final screen will be the most important one.
Over here, we need to define the parameters to running this.
This step is synonymous with running a Python script on your command line (i.e. Run -> cmd). When you run a Python script on your command line, you usually do something like this.
$ cd /Users/Desktop/someFolder/
$ python myawesomescript.py
On the first line, we change the directory to where the script is located, and the second line we run the script in the directory.
When we use the "python" command, we're actually calling the Python interpreter to run the Python script (i.e. myawesomescript.py).
Now going back to that final step, this is what we put in each input boxes.
The first two boxes equate to the python myawesomescript.py step on the command line. Here's a StackOverflow answer to finding the location of your Python interpreter.
The third box is the cd /Users/Desktop/someFolder/ step on the command line. Simply place the full directory of your script there.
Click Next and Finish your setup. There are still some final steps to make sure the scheduling works.
To make sure that the script runs as expected, this step is (sometimes) necessary.
Double click on the script to open the options window. Over there, please select the option of "Run whether user is logged on or not" to ensure that the script runs even if you're not logged in when the PC starts up.
Next, on the bottom right, select the option to configure to Windows 10 or whichever version of Windows you're on.
You're done!
To test if the script runs as expected, you can either schedule it for 2-5 minutes after and then check its "Last run time" to verify that it ran. You can also just click the "Run" option at the right sidebar (bottom right of the 1st screenshot in this post).
Like the post? Consider donating to fund the maintenance of this website: