How to Schedule Python (.Py) script using Windows Task Scheduler

Schedule Python script using Task Scheduler Automation

Today in this article, we will see how to Schedule Python script using Task Scheduler. Windows Task Scheduler is a scheduler that helps automate repetitive tasks and reduces the manual effort of running the task in the form of a script or etc.

There are many advantages of the Tasks scheduler, some of them are listed below,

  • Automate the Job/Task/Script
  • Schedule tasks at a predefined schedule.
  • Schedule the task as per predefined priority.
  • Improves turnaround time by a running script at a convenient time. like nightly runs etc.

Let’s see in detail how to schedule the python script through the Windows Task scheduler.

Today in this article, we shall see below,

Create Tasks in Task Scheduler

Open the Tasks Scheduler Windows -> search for Task scheduler or type taskschd.msc using Windows+R.

Schedule Python script Windows task scheduler

Click on “Create Task”

automate Python script Windows task schedulerScheduling a py file on Task Scheduler in Windows 10

Define the below attributes,

  • Name – Define Application Name,
  • Description – Define a description of the task
  • Security options– Please select the appropriate Radio button. We shall select the option “Run whether the user is logged on or not”
    • Run with the highest privileges – To run the program with administrator privileges, its recommended to use this option
How to Schedule Python Script using Windows Schedule

It’s advised to use the highest privileges to run the python script to avoid any issues.

Configure Trigger in Task Scheduler

Click on the “Trigger” tab and define the configuration

In the next step, please click on the “Trigger” tab and click on “New” to create a new trigger.

You can define the condition of when to trigger the given task for example “On a schedule” or “On an event” or “on logon” or “on an event” etc.

You need to define the schedule for your script like,

  • One time or
  • Daily or
  • Weekly or
  • Monthly

automate Python script Windows task scheduler

Configure Action – Python script in Task Scheduler

Click on the “Action” tab and define the configuration

In the next step, please click on the “Action” tab and click on “New” to create a new action.

Please specify the following parameters:

  • Action: Start a program
  • Program\script: [Python location path with name]
  • Add arguments (optional): [Add command line argument if any]
  • Start in(optional): [directory path where python script exist]

I have kept my python file at below path,

C:\Test\File\python-loader
schedule Python script Windows task scheduler

Configure Condition – Python script in Task Scheduler

Click on “Condition” tab and define the configuration

In the next step, please click on the “Condition” tab and select the appropriate options.

These additional conditions let you configure the task based on specified selection. The task will not run if any conditions specified here are not met..

blank

That’s all, you are all set to execute the python script as per the defined configuration.

Do you have any comments or ideas or any better suggestions to share?

Please sound off your comments below.

Happy Coding !!



Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.



Leave a Reply

Your email address will not be published. Required fields are marked *