Free

Free coded apps to suit all. No sign up, no email, usable offline, updates when I can, feedback welcome. Send feedback

How-to

How to schedule a Python script on Windows

Create a script job in Schedule by Zaweba, pick Python, choose the file or paste the code, and set a plain-English timetable. Output is kept in the history.

How to schedule a Python script on Windows

In Schedule by Zaweba, create a script job, pick Python as the language, then either choose your .py file or paste the code straight into the job, and give it a timetable such as every weekday at 7:00. Schedule finds a real python.exe for you, runs the script on time and keeps its output and error output in the history, so you can see what it printed on every run.

That last part is the reason many people move their Python scripts to it. A script that runs silently and fails silently is worse than no script at all.

Before you start

You need Python installed on the PC, and the script should already work when you run it yourself. If it uses extra packages, install them for the same Python that Schedule will use. Schedule looks for a real python.exe automatically, and if you keep Python somewhere unusual, or have several versions and want a particular one, Settings > Scripts lets you set the path to any interpreter.

Setting up the job

Make a new job and choose a script job. Pick Python. Then decide where the code lives.

Choosing a file is best for a script you also edit and run elsewhere, perhaps under version control. The job runs whatever is in the file at the time.

Pasting the code into the job suits small scripts that only exist to be scheduled, such as a few lines that tidy a folder or fetch a file. Scripts typed into jobs are saved before they run, so what runs is exactly what you see in the editor.

Writing the timetable

Timetables are written as you would say them: every day at 6:00, every 15 minutes between 9:00 and 17:00, last Friday of the month, first working day of the month. A step-by-step builder stays in sync with the text, and a word Schedule does not understand is reported, never guessed at. If you think in cron, you can type a 5-field cron expression instead.

Below the timetable, Schedule describes it back in words and lists the next 10 run times. Read them before saving. It is the easiest way to catch a job that would also run at weekends.

A job can start on an event instead of a time: at login, when a file appears in a folder, when a USB drive is connected and more. A script that processes files as they arrive is a natural fit for the folder trigger.

Seeing what the script did

Every run is recorded with what started it, start and end, duration, attempt and exit code, together with the captured output and error output. By default the last 64 KB of each stream is kept, and history is kept for 90 days. Filter by job, by status or by text to find a particular run.

This changes how you write scripts. Print what the script is doing, and let errors reach the error output rather than hiding them. If a script exits with a non-zero code when something goes wrong, the run is marked as failed, a Windows notification appears, and an email can be sent through your own mail server if you set one up.

Making it dependable

A few options turn a script that usually works into one you can trust. Retries repeat a failed run after a delay, which helps with network hiccups. A time limit stops the job and every process it started if it runs far too long. An option stops a second copy starting while one is still going. Catch-up runs a missed job once as soon as Schedule is running, if the PC was off at the time.

Chains let one job follow another. Run a clean-up script only after a download script succeeds, or an alert job only when something fails, without writing that logic into Python yourself.

Before you rely on it

Use Run now once and read the history entry. Check that the output is what you expect and the exit code is zero. If the script reads or writes files, make sure it uses full paths or sets its own working folder, since it may not start in the folder you expect.

Schedule runs as you from the notification area and needs no administrator rights, so jobs run while you are signed in to Windows. For scripts that must run with the PC asleep, a job can wake it from sleep, as long as Windows' Allow wake timers power setting is on.

Set up like this, a Python script on Windows runs on time and leaves a clear record behind it, every time.