How to run your Shell script automatically after logging to mac?

trupti bhatt
1 min readJan 30, 2021

If you have some dedicated mac machines for automation testing and every time you have to run some scripts as a part of prerequisites (Some setup related things). What will you do? Probably you will run that script manually for the very first time. It will work but what if the system restarts? Will you run your script manually? NO….. here is the solution.

Solution :

Phase 1: Create a script using Automator. (video:https://youtu.be/nY20Nme72G0)

  • Go to Finder.
  • Select Application.
  • Double click on Automator.
  • Double click on application from popup.
  • Click on utility under library section.
  • Select run shell script from second pane.
  • Write/Paste your script which you want to run.
  • Click on File →Save. Give the name of the file and location to store. File format will be application.

Your script is ready……

Phase 2 : Associate your script with the login action.

  • Go to System preferences.
  • Search for login items.
  • Select the user for which you want to run script automatically.
  • Click on (+) Plus sign from the second pane. (If you hover on it , you can see “Add an item to the login item list.”) One popup will be opened.
  • Browse to the path of the application (script) which you have created using above steps and click on Add button. Your Script is added under the login item list box.

Note: (You can restart the system and login with the selected user to cross verify whether the script has been automatically started or not)

Enjoy automating your test !

--

--