No doubt the 21st century is all about Python, Machine Learning and Artificial Intelligence. While working on these technologies is pretty exciting but there are processes that you perform on a day to day task. Say, for example, downloading a file from a particular location daily for updated content or transferring files from one drive to another which is pretty boring when the number of files is more.
So to avoid the boring situation where you have to do a repetitive task in your day to day job, you can automate them with few lines of code in python and scheduling that particular python script to run at a specific time daily, weekly or monthly depending on the need. Below are the steps which you can follow for automating python script to run at a specific time every day using Windows Task Scheduler.
Automating Python Script to Run at Specific Time Every Day using Windows Task Scheduler
- First, write your python script and save it with a .py extension. The script we are using here is for copying a file from one folder to another folder using python. You can check that script here.
- Now open Windows Task Scheduler (by typing Task Scheduler in search)
- Once opened, on the right side in the Actions tab, click on Create Basic task. Once you click, the create basic task wizard opens up.
- This has four tabs namely: Create a basic task, Trigger, Action and Finish.
- On the Create a basic task tab you can define the name and description of the python script that you are automating.
- On the Trigger Tab, you can define the frequency like when you want to run the python script i.e. Daily, Weekly, Monthly etc. etc. Here i have chosen Daily.
- When you click next, under the Trigger Tab, you have to provide the time as well. The exact time when you want your python script daily.
- On the Action Tab, you have to mention what action you want to perform out of three options provided.
- Start a Program
- Send an email
- Display a message
- Choose Start a Program.
- Once you click next, a tab opens up under the Action tab and this is the important part of the whole process.
- Here in this step, you have to provide the path to two different files.
- The first path is for the Python.exe and second is for you python script that you want to run. For this, we focus on the Program/script option and Add Argument option.
- In the Program/Script, we browse the path to the Python.exe file. for me, it’s available in “C://Python37//python.exe”
- Second, we pass the path to our script in Add Arguments. The important thing here to note is that we have to pass the path here in inverted commas (” “) and for Program/Script option, it’s optional.
- Now click next and finally finish the process.
- Now if you want to see the scheduled task, you can click on Task Scheduler Library on the left pane and then in the middle pane, you can look for the name of your task.
- There are other options that you have to look for, to configure the task schedule which you can find on double-clicking the task name on the middle pane.
Hope this helps you out. If you need more help in automating python script to run at a specific time every day using Windows Task Scheduler, feel free to reach me via the comments section.
Leave a Reply