Run Schedule Jobs Using Mac Automator, An Alternative To Cron

Run Schedule Jobs Using Mac Automator, An Alternative To Crontab

Cron is a well-known tool for scheduling jobs in Unix-like operating systems. However, cron was depreciated in macOS. As the documentation states, although it is still supported, cron is not a recommended solution.

In addition to the reason, if you don’t have permission to install the crontab, you will see the error message “Operation not permitted” when saving the crontab file. This post will show you how to run scheduled jobs using Mac Automator, an alternative to cron.

Step 1. Open Automator

Just type “Automator” in the Spotlight search bar and press Enter to open Automator.

Step 2. Grant Full Disk Access Permission To Automator And Calendar

Click Apple Menu > System Settings > Privacy & Security > Full Disk Access, then allow Automator and Calendar to access the full disk.

Step 3. Create A New Application

Choose “Application” and click “Choose”.

Step 4. Create A Shell Script And Save

Search “shell” in the search bar and write the shell script in the editor. If you manage Python projects with pipenv like me, you can directly copy the following script and paste it into the editor.

Assuming that you receive an error “zsh:8: command not found: python”, it means the system cannot find executable Python. You can use the “pipenv –venv” command to find the location of the virtual environment and replace the path in the script.

After completing the script, click “run” button to test the script. Then click “File” -> “Save” to save the application.

# Navigate to the proejct folder
cd /Users/username/project
# Activate the pipenv environment
source /Users/username/.local/share/virtualenvs/project_env
# Make the script executable
chmod +x scheduler.py
# Run the Python script
python your_python_script.py
# If the system cannot find executable Python, use the following command and replace the path in the script:
# /Users/username/.local/share/virtualenvs/project_env/bin/python3.10 your_python_script.py

By the way, some tutorials create a workflow document as the first step, then convert it to an application. However, it may cause an error message like:

You can't open the application "your_app_name" because it may be damaged or incomplete.

Step 5. Open Calendar And Create a New Event

Click the “+” button to create a new event.

Step 6. Add Event Settings

In the event settings, choose “Custom” for the alert and select “Open file” from the dropdown menu. Then, select the Application you saved in the step 5. Then everything is done, your scheduled job will run at the specified time.

A data scientist working in a retail company, with experience in web design and marketing. Recently dives into cryptocurrency and quantitative investing.