-
-
Notifications
You must be signed in to change notification settings - Fork 2
Setting Up Automation on macOS
This guide will walk you through the steps to configure cron to automatically run any file on login, once per day, or hourly.
-
Open a terminal.
-
Edit the cron table by running the following command:
crontab -e
-
If prompted, choose your preferred text editor.
-
Configure the cron job:
-
To run a file on login:
-
Add the following line to the cron table:
@reboot /path/to/your/file.sh
Replace
/path/to/your/file.sh
with the actual path to the file you want to run on login.
-
-
To run a file once per day:
-
Add the following line to the cron table:
0 0 * * * /path/to/your/file.sh
Replace
/path/to/your/file.sh
with the actual path to the file you want to run once per day.
-
-
To run a file hourly:
-
Add the following line to the cron table:
0 * * * * /path/to/your/file.sh
Replace
/path/to/your/file.sh
with the actual path to the file you want to run hourly.
-
-
-
Save the cron table and exit the text editor.
-
The cron job is now scheduled to run the specified file at the specified time interval.
That's it! You have successfully set up cron to auto-run a file on Linux.
Creating a shell script to run multiple python projects at once, optional steps for opening programs and creating a shortcut to run on demand from desktop
This guide will walk you through the steps to create a shell script that can run multiple Python projects. Additionally, it includes optional steps for opening programs.
Before you begin, ensure the following:
- Python is installed on your system.
- The Python projects you want to run are installed and added to the system's PATH environment variable. Projects installed with pip are typically already added to the system's PATH environment variable.
-
Open a text editor and create a new file called
run_projects.sh
. -
Add the following lines to the file:
#!/bin/bash
python -m project1
python -m project2
python -m project3
Replace project1
, project2
, and project3
with the actual names of your Python projects. You can add as many lines as needed for each project.
-
Save the file.
-
(Optional) Steps to Open Programs:
If you want to open programs (e.g. program1, program2, program3), add the following lines to the script.
open -a program1
open -a program2
open -a program3
Replace program1
, program2
, and program3
with the actual names of the programs.
-
Make the Script Executable:
Open a terminal and navigate to the directory where the script is saved.
Run the following command to make the script executable:
chmod +x run_projects.sh
-
Create a Folder in Desired Location:
- Open Finder and navigate to the desired location where you want to create the folder (e.g.,
/Users/YourUsername/Projects
). - Right-click in the desired location and select "New Folder".
- Name the folder "Run Projects" (or any desired name).
- Open Finder and navigate to the desired location where you want to create the folder (e.g.,
-
Move the Script to the Folder:
- Open another Finder window and navigate to the directory where the
run_projects.sh
script is saved. - Drag the
run_projects.sh
file into the "Run Projects" folder created in the previous step.
- Open another Finder window and navigate to the directory where the
-
Create a Shortcut on the Desktop:
- Navigate to the "Run Projects" folder in Finder.
- Right-click on the
run_projects.sh
file within the "Run Projects" folder. - Select "Make Alias".
- A shortcut with the name "run_projects.sh alias" will be created.
- Drag the shortcut to the desktop.
-
Run the Script:
- Double-click the shortcut on the desktop to execute the script.
- The script will run in the terminal, executing the specified Python projects (and opening programs if included).
That's it! You have successfully created a shell script to run multiple Python projects on macOS, and created a shortcut on the desktop for easy execution of the script. The "Run Projects" folder can be created in any desired location on your system.