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 Implementation
Create a Python file, for example: gmail_automation.py, and write your script inside it. Make sure everything works as expected when you run it manually, this is the script that will be scheduled to run automatically
Alternatively, you may use any Python script that you’d like to schedule.
import webbrowser
# Gmail URL
url = "https://mail.google.com"
# Path to your Chrome browser
chrome_path = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
# Register and open Chrome browser with Gmail
webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(chrome_path))
webbrowser.get('chrome').open_new_tab(url)
Note: Change your chrome_path according to the location on your system if you want to use the above Python Script.
Now there are two ways to schedule a script:
- Using batch files.
- Using Windows Task Scheduler.
Method 1: Using batch file
Step 1: Create a Batch File.
Open Notepad and add the following (update the paths):
"Path where your Python exe is stored\python.exe" "Path where your Python script is stored\script name.py"
pause
Example of the batch file:

Step 2: Save the File
Save it with a .bat extension, e.g. open_gmail.bat.
To check if the scripts is working or not, navigate to the .bat file and open it (or double click on it) and it should launch the gmail in chrome browser.
Method 2: Using Windows Task Scheduler.
Step 1: Open Task Scheduler by navigating to:
Start Menu > Administrative Tools > Task Scheduler
Or search Task Scheduler in the Start menu.

Step 2: Create a New Basic Task
- Click "Create Basic Task..."
- Give your task a name (e.g. "Open Gmail Daily") and a description.
- Click Next.

Step 3: Set the Trigger
- Choose "Daily"
- Set the start time when you want the script to run.
- Click Next.

Step 4: Select the "Start a Program" option and click Next.
If you created a batch file earlier, enter its full path in the Program/script field (e.g., C:\path\to\yourbatchfilename.bat), then click Next and Finish. Your Python script will now run daily at the scheduled time.
In this section, you'll need the file location of the following files:
- python.exe - The path where python.exe is stored.
- the path where your python script file is stored.
You can simply get both the paths by running command- "where python" in the command prompt and copy the paths form there.
In our case :
Path of python.exe - C:\Python39\python.exe
Path of my python script - D:\Tutorials\Python
Step 5: Add respective file locations as shown in the figure below and arguments input, specify your python script name.

Step 6: In the next tab, you just need to verify your Inputs and then click on 'Finish'.

That's it, your Python Script is now Scheduled and will be executed daily at your Specified time. Here is the Screenshot of our Python Script that got executed.
