Schedule Python Script using Windows Scheduler
Last Updated :
24 Feb, 2021
In this article, we are going to schedule a python script using a windows task scheduler, i.e. make it launch automatically at a certain time or after a certain time period.
Before starting we need to know the following point:
- Python Script: It is a bunch of python code meant to be directly executed by the user from the command line. Most of these are automation scripts, meant to automate certain tasks. These usually contain a few lines of code.
- Windows Scheduler: Windows Task Scheduler is a Microsoft Windows component or program which gives the user ability to schedule certain scripts or programs and automatically launch them at a certain time. It is used majorly to automate certain tasks like daily planners, monthly data scraping, etc.
Let’s implement with Step-wise:
Step 1: Make a python script
First, we’ll make the python script that we want to schedule. If you have already made the script, skip this section. If not, you can make your own python script or follow mine.
Here we made a python script that fetches a random inspirational quote image from a folder where I’ve saved a couple of them and displays it. You’ll need the following python packages/modules: tkinter, PIL, os, random.
Python3
from tkinter import *
from PIL import ImageTk, Image
import os
import random
name = random.choice(os.listdir(
"C:\\Users\\NEERAJ RANA\\Desktop\\quotes_folder\\" ))
file = "C:\\Users\\NEERAJ RANA\\Desktop\\quotes_folder\\" + name
root = Tk()
canvas = Canvas(root, width = 1300 , height = 750 )
canvas.pack()
img = ImageTk.PhotoImage(Image. open ( file ))
canvas.create_image( 20 , 20 , anchor = NW, image = img)
root.mainloop()
|
Remember to change the folder path according to the folder location on your system.
Now, there are two ways to schedule the script. The first method involves making a batch file, the other does not. If you don’t want to make a batch file, you can skip stepping 3.
Step 2(Optional): Make a batch file
A batch file is used to execute commands with the command prompt. It contains a series of commands in plain text you would normally use in the command prompt and is generally used to execute programs.
We are going to make a batch file to run our python script.
- First, open up any text editor.
- Next, enter the following lines in an empty file:
"C:\Python38\python.exe" "C:\Users\NEERAJ RANA\Desktop\GFG_Articles\scheduler\quote.py"
pause
The first string is the path to the python executable on your machine and the second one is the path to your saved python script. If you don’t know the path to your python executable, open up a command prompt and enter the following command: where python.

where command
If you see multiple paths, use any one of them. Also, change the path to your saved python script according to your system. The pause command is used to suspend the processing of the batch program and wait for the user’s input. And lastly, save this file with a .bat extension.
Step 3: Scheduling the script
- Open up the Task Scheduler application. It should look something like this:

- Click “Create Basic Task…” in the Actions tab on the right.
- Enter a suitable name and description to the task in the given fields and click next.
- Choose the frequency with which you want to want your task to be executed. You can choose between daily, weekly, monthly, etc and then click next.
- Choose the start date and time when you want the task to be triggered. Also, choose after how many days you want the task to repeat/recur and click next.
- Choose “Start a program” in “What task do you want to perform?” and click next.
- If you made a batch file in step 2, just enter the path to the batch file in the program/script section. If you skipped step 2, enter the path to the python executable in the program/script section and enter the path to your python script file in the “Add arguments (optional)” section.
- If your script has some dependencies installed in some folder, like browser executable, you can include the folder path in the “Start in (optional)” section and click next.

If you made a batch file

If you didn’t make a batch file
- 8: Lastly, check all the entered values and click finish.
Now, at your chosen time, your script will execute.

Similar Reads
Schedule a Python Script to Run Daily
In this article, we are going to see how to schedule a Python Script to run daily. Scheduling a Python Script to run daily basically means that your Python Script should be executed automatically daily at a time you specify. Step-by-Step ImplementationCreate a Python file, for example: gmail_automat
3 min read
Shell Scripting - Scheduling Commands
We need to run the scripts frequently in order to maintain the system infrastructure's cleanliness and security when using a UNIX-based system. These repetitious chores involve system backups, health monitoring, as well as other upkeep duties. Automation is the finest and quickest technique to accom
3 min read
Task Scheduler Using HTML, CSS and JS
In this article, we will create a Task Scheduler web application using HTML, CSS and JavaScript. This is an application which can store tasks provided by user and classified them as low priority, middle priority, and high priority. User also can provide a deadline for the task. User also can mark do
3 min read
Scheduling Python Scripts on Linux
Sometimes we need to do a task every day, and we can do these repetitive tasks every day by ourselves, or we can use the art of programming to automate these repetitive tasks by scheduling the task. And today in this article we are going to learn how to schedule a python script on Linux to do the re
3 min read
Fix: Operator Refused the Request Error in Windows Task Scheduler
The "Operator refused the request" error in Windows Task Scheduler can prevent scheduled tasks from running correctly, often caused by permission issues, incorrect user configurations, or a corrupted Task Scheduler library. This error typically occurs when the user account used to run the task doesn
6 min read
Visual TimeTable using pdfschedule in Python
Scheduling is the greater part of life and having a timetable helps in setting up a routine. Boring timetables or routines made just in mind don't usually help. Having a flashy and visually appealing timetable attracts and hence pushes us to look and follow. This article presents an easy way to prod
3 min read
How to Create Time-Table Schedule using HTML?
A time table or schedule is essential for organizing tasks, events, or classes. Weâll create a basic time-table layout using HTML. A Table is an arrangement of rows and columns. Anyone can create a table by knowing the basics of HTML(HyperText Markup Language). In HTML we can use the <table> t
3 min read
Batch Script - Create String
In this article, we are going to learn how to create a String using Batch Script. Batch Script :@echo off set str=Geeks for Geeks echo %str% pauseBy using ' set ' we are getting input of any string.Ex: set str=input stringIn the next line, we are using ' echo %str% ' for printing our input string.Th
1 min read
How to Execute Ruby Script in Windows?
Ruby is a dynamic, object-oriented programming language and a Ruby script is a plain text file containing code written in the Ruby programming language. Ruby scripts are saved with a .rb extension. Ruby scripts can be used to write programs as simple as "Hello, World!", to complex applications, such
2 min read
How to Schedule Tasks Using at Command in Linux
The at command in Linux is used to schedule one-time tasks to be executed at a specified time in the future. It allows users to submit a command or script for execution at a later time, offering a convenient way to automate tasks without the need for complex cron jobs. The scheduled jobs are managed
5 min read