Running Script on macOS Startup | Information Technology from Valdemar

This article is written for those who were searching for a detailed and simple for the understanding guide on how to run a script on a macOS startup before the user logs in.

This guide covers commands running using the iTerm2 terminal emulator installed on the macOS operating system.

Login into the system under an account with administrator rights and run the terminal emulator.

Now create a script that will contain the necessary scripts to run when booting macOS, using the command:

sudo vim /Users/valdemar/Documents/Scripts/run-service.sh

Please note that in this manual a script called “run-service.sh” is created in the user’s home directory. You can create a script in any convenient place for its permanent storage.

Specify the password for the account and press “Enter”.

Press on the “i” button to enter the editing mode, then add the scripts necessary for execution when booting macOS.

Now press the “Esc” button to exit the editing mode, and then enter “: x” and press the “Enter” button to save the changes and exit the editor.

Enable the execution of the “run-service.sh” file using the command:

sudo chmod +x /Users/valdemar/Documents/Scripts/run-service.sh

Now you need to use the Cron task scheduler to schedule the script to run after the operating system starts.

Open the task scheduler using the command:

sudo crontab -e

Press on the “i” button to enter the editing mode, then add the line with the “@reboot” parameter and specify the full path to the previously created script:

@reboot /Users/valdemar/Documents/Scripts/run-service.sh

Now press the “Esc” button to exit the editing mode, and then enter “: x” and press the “Enter” button to save the changes and exit the editor.

Now the script will automatically run when macOS boots up even before the user logs in.

Author

Hi, I’m Vladimir Mikhalev, but my friends call me Valdemar. I have a lot of experience in the design and maintenance of various information systems. On my website, you will find detailed and clear guides for setting up IT solutions. Dive into the ocean, full of positive and technology! For cooperation: callvaldemar@gmail.com

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.