In earlier tutorials we built automation scripts for backups, reports and price monitoring. But there's one catch: every time, you still have to open a terminal and press Enter yourself. If you have to remember to run it manually each morning, it isn't really "automatic" yet.
This tutorial shows you how to make Python scripts run on a schedule — the computer executes them at the right time with zero clicks. We'll cover two methods: the pure-Python schedule library (for machines that stay on), and the built-in Windows Task Scheduler (for running automatically at a set time each day).
Method 1: The schedule library (keep it running)
If your computer stays on all day (a shop's till or office PC), the easiest route is the schedule library, which lets Python keep track of time. Install it first:
When you see Successfully installed schedule, you're ready. Then create a file called auto.py:
Line by line
- import schedule — loads the scheduling library.
- def job(): — defines what you want to automate; drop in the backup, report or monitoring code you learned earlier.
- schedule.every().day.at("09:00").do(job) — runs once a day at 9:00 AM. Minute and weekly options are covered below.
- while True — keeps the program alive, constantly checking whether it's time.
- schedule.run_pending() — runs the task when the time arrives.
- time.sleep(1) — checks once per second without eating too much CPU.
Method 2: Windows Task Scheduler (run on startup)
If you'd rather not keep a terminal open (or the machine shuts down at night), Windows' built-in Task Scheduler is a better fit. It can launch Python at a set time, and even wake the computer to do so.
Steps:
- Open Task Scheduler — press the Windows key and type "Task Scheduler".
- Create Basic Task — click "Create Basic Task" on the right and give it a name (e.g. "Daily report").
- Set the trigger — choose "Daily" and pick a time (e.g. 09:00).
- Choose the action — select "Start a program", enter python in the program box and C:\scripts\auto.py in the arguments box (use your own path).
- Finish — done; it now runs automatically every day.
How to write the timing
The schedule library supports many time settings. Common ones:
- Every minute — schedule.every().minute.do(job)
- Every hour — schedule.every().hour.do(job)
- Daily at a set time — schedule.every().day.at("09:00").do(job)
- Every Monday — schedule.every().monday.at("08:30").do(job)
- Every 10 seconds — schedule.every(10).seconds.do(job)
Common problems
- Task Scheduler says it can't find python — use the full path in the program box, e.g. C:\Users\yourname\AppData\Local\Programs\Python\Python311\python.exe. Run where python in Command Prompt to find the real location.
- The schedule program must stay running — yes, Method 1 relies on while True to stay alive. If you don't want that, use Method 2's Task Scheduler.
- It won't run if the machine sleeps or shuts down — in Task Scheduler you can tick "Wake the computer to run this task", so it powers on at the right time.
Summary
Python Tutorial: From today, every backup, report and monitoring script you've written can run on a schedule, so you never have to remember to press a button again. Use the schedule library for always-on machines, and Windows Task Scheduler for daily automatic runs on startup. Set it once and it's truly hands-off from then on.