Search code examples
pythonautomationscheduling

How to schedule code to run at a specific time every day?


Need help to run code that automatically starts at 4:30pm every day on Python Visual Studio Code. I don't want to print anything I just want to execute my commands like: pg.keyUp('enter').

For example.

import schedule
import time

def job():
    pg.keyUp('enter')                    < This no work

schedule.every(60).seconds.do(job)

while True:
    schedule.run_pending()
    time.sleep(1)

Only works with printing text.


Solution

  • You can use crontab to run the script at 16:30 every day.

    30 16 * * * /usr/bin/python script.py
    

    Change script.py to the full python file location

    Here is a guide on how to use crontabs

    https://towardsdatascience.com/how-to-schedule-python-scripts-with-cron-the-only-guide-youll-ever-need-deea2df63b4e?gi=36e3b90594a4