Mac and Linux users can use CronTab to schedule Python scripts! CronTab is preinstalled on MacOS.
> Open System Preferences
> Click Security and Privacy
> Click File Disk Access
> Click the + button
> Press Command + Shift + G
> Type /usr/sbin/cron
> Click Open
- Launch Terminal.
- Type
crontab -e
to launch CronTab editor. - Press
i
to edit - Type
0 * * * * cd ~/Documents/portfolio/craigslist_chairs && /Users/taekunkim/opt/anaconda3/bin/python3 script.py
0 * * * *
sets the schedule to every hour of every daycd ~/Documents/portfolio/craigslist_chairs
brings CronTab to the directory where my script is saved/Users/taekunkim/opt/anaconda3/bin/python3 script.py
is the same as typing inpython3 script.py
. However, CronTab may not recognizepython3
, so we must type in the directory wherepython3
is saved. You can find the directory by typingwhich python3
into Terminal.
- Press
esc
- Enter
:wq
That's it!