Post

MacOS - Running a script at Startup

Steps to execute a script on startup:

  1. Create the Shell Script:
    • Create a file named start_jekyll.sh in your Jekyll site directory:
    1
    
     nano /Users/Sakharam.Shinde/github/sakharams.github.io/start_jekyll.sh
    
  2. Add the following content:

    1
    2
    3
    
     #!/bin/bash
     cd /Users/Sakharam.Shinde/github/sakharams.github.io
     /usr/local/bin/bundle exec jekyll serve --watch > /tmp/jekyll-serve.log 2>&1
    
  3. Make the script executable:

    1
    
     chmod +x /Users/Sakharam.Shinde/github/sakharams.github.io/start_jekyll.sh
    
  4. Create a the Plist File ~/Library/LaunchAgents/com.user.jekyllserve.plist:
    • Update the plist file to call the shell script:

```xml <?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”>

Label com.user.jekyllserve ProgramArguments /Users/Sakharam.Shinde/github/sakharams.github.io/start_jekyll.sh RunAtLoad KeepAlive StandardOutPath /tmp/jekyll-serve.log StandardErrorPath /tmp/jekyll-serve.log
  1. Load the Launch Agent:

    1
    
     launchctl load ~/Library/LaunchAgents/com.user.jekyllserve.plist
    
  2. Verify and Check Logs:
    1
    
     launchctl list | grep com.user.jekyllserve
    
  3. Check the log file:

    1
    
     tail -f /tmp/jekyll-serve.log
    
  4. To unload the agent

    1
    
     launchctl unload ~/Library/LaunchAgents/com.user.jekyllserve.plist
    
This post is licensed under CC BY 4.0 by the author.