Best way to schedule Python scripts on macOS?

Started by Alex Kumar · 3 months ago

A
Alex Kumar 4 months ago
I want to run a data sync script every hour. Is launchd better than cron on Mac?
M
Michael Torres 3 months ago
launchd is the macOS-native way and more reliable. Create a plist in ~/Library/LaunchAgents/. But honestly, for simple scheduling cron still works fine: `crontab -e` and add `0 * * * * /usr/bin/python3 /path/to/script.py`.
A
Anna Kowalski 3 months ago
For complex scheduling with error handling, I use the Python `schedule` library. It runs in a loop but gives you clean syntax:\n\n```python\nimport schedule\nschedule.every().hour.do(sync_data)\nwhile True:\n schedule.run_pending()\n time.sleep(60)\n```

Sign in to reply to this topic.

We use cookies to enhance your experience. By continuing to use this site, you agree to our use of cookies.