In Terminal: crontab -e. Add a line:
# minute hour day month weekday command
0 8 * * 1-5 /opt/anaconda3/bin/python /Users/you/scripts/morning_report.py >> ~/cron.log 2>&1
This runs at 08:00 on weekdays.
python.exe; arguments: C:\path\to\morning_report.py.A scheduled script can't ask the user for input. Hard-code paths or read them from environment variables / a config file.
import logging
from datetime import datetime
logging.basicConfig(
filename="morning_report.log",
level=logging.INFO,
format="%(asctime)s %(levelname)s: %(message)s",
)
logging.info("Starting morning report")
# ... do work ...
logging.info(f"Completed in {(datetime.now()-start).total_seconds():.1f}s")
For a long-running script that schedules itself:
import schedule, time
def job():
print("Running daily report")
schedule.every().day.at("08:00").do(job)
while True:
schedule.run_pending()
time.sleep(60)
Useful inside Docker containers; for laptop use, cron / Task Scheduler is simpler.
Schedule a tiny Python script (one line: append today's date to a log file) to run daily. Confirm it ran tomorrow.