Run a shell script when I log onto the computer macOS Sequoia

Hello World!

I would like to run a shell script when I logon to my computer running macOS Sequoia. Is there anyway to do this and if so, could you point me in the right direction to some information or guides?

Much gratitude in advance for any and all help and suggestions!

iMac 27″, macOS 15.5

Posted on Jun 28, 2025 12:00 PM

Reply
Question marked as Top-ranking reply

Posted on Jun 28, 2025 12:32 PM

Running a shell script on login in macOS Sequoia (or any recent macOS version) is certainly doable, and there are a few clean ways to go about it depending on what you need—whether it’s for just your user session or system-wide. The most straightforward and reliable method is using LaunchAgents, which is the Apple-sanctioned way to run scripts or executables at login for a specific user.


Here's an example which should get you started on developing your own for your specific needs:


  • You, of course, would start with a shell script. In this example, we will create one called: hello.sh
  • Its contents would be something like: echo "Hello, World!" >> ~/Documents/hello_output.txt
  • Save it somewhere safe, like: ~/Scripts/hello.sh
  • Don’t forget to make it executable: chmod +x ~/Scripts/hello.sh
  • Next, you will want to create a LaunchAgent plist file in : ~/Library/LaunchAgents/
  • Create a file like `com.yourname.helloscript.plist` with the following content:


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

<key>Label</key>

<string>com.yourname.helloscript</string>

<key>ProgramArguments</key>

<array>

<string>/Users/yourusername/Scripts/hello.sh</string>

</array>

<key>RunAtLoad</key>

<true/>

<key>StandardOutPath</key>

<string>/tmp/helloscript.out</string>

<key>StandardErrorPath</key>

<string>/tmp/helloscript.err</string>

</dict>

</plist>


Replace `yourusername` with your actual macOS short username.


  • Next, you will want to load the LaunchAgent, To do so, open the Terminal app, and run:
    • launchctl load ~/Library/LaunchAgents/com.yourname.helloscript.plist

This will set it up to run every time you log in.


As far as learning guides ...


If you like to start with the *straight-from-Apple* material, three that come to mind are:

  1. Shell Scripting Primer on the Apple Developer site
  2. Intro to Shell Scripts article in Apple Support, and
  3. The launchd script-management guide for learning how to make your scripts run on login, schedule, or system-boot.


For deeper dives—and tips that feel more “Mac admin” than “Unix 101”— I suggest Armin Briegel’s Scripting OS X blog. In addition, you may like: Kandji’s Introduction to Mac Shell Scripts.

2 replies
Question marked as Top-ranking reply

Jun 28, 2025 12:32 PM in response to Batman-15

Running a shell script on login in macOS Sequoia (or any recent macOS version) is certainly doable, and there are a few clean ways to go about it depending on what you need—whether it’s for just your user session or system-wide. The most straightforward and reliable method is using LaunchAgents, which is the Apple-sanctioned way to run scripts or executables at login for a specific user.


Here's an example which should get you started on developing your own for your specific needs:


  • You, of course, would start with a shell script. In this example, we will create one called: hello.sh
  • Its contents would be something like: echo "Hello, World!" >> ~/Documents/hello_output.txt
  • Save it somewhere safe, like: ~/Scripts/hello.sh
  • Don’t forget to make it executable: chmod +x ~/Scripts/hello.sh
  • Next, you will want to create a LaunchAgent plist file in : ~/Library/LaunchAgents/
  • Create a file like `com.yourname.helloscript.plist` with the following content:


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

<key>Label</key>

<string>com.yourname.helloscript</string>

<key>ProgramArguments</key>

<array>

<string>/Users/yourusername/Scripts/hello.sh</string>

</array>

<key>RunAtLoad</key>

<true/>

<key>StandardOutPath</key>

<string>/tmp/helloscript.out</string>

<key>StandardErrorPath</key>

<string>/tmp/helloscript.err</string>

</dict>

</plist>


Replace `yourusername` with your actual macOS short username.


  • Next, you will want to load the LaunchAgent, To do so, open the Terminal app, and run:
    • launchctl load ~/Library/LaunchAgents/com.yourname.helloscript.plist

This will set it up to run every time you log in.


As far as learning guides ...


If you like to start with the *straight-from-Apple* material, three that come to mind are:

  1. Shell Scripting Primer on the Apple Developer site
  2. Intro to Shell Scripts article in Apple Support, and
  3. The launchd script-management guide for learning how to make your scripts run on login, schedule, or system-boot.


For deeper dives—and tips that feel more “Mac admin” than “Unix 101”— I suggest Armin Briegel’s Scripting OS X blog. In addition, you may like: Kandji’s Introduction to Mac Shell Scripts.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Run a shell script when I log onto the computer macOS Sequoia

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.