0

I want to run a shell script on mac startup. For that i have created a shell script and plist file. I have copied the plist to ~/Library/LaunchAgents/com.example.exampld.plist. It has all required permissions.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>Label</key>
   <string>com.example.exampld</string>
   <key>ProgramArguments</key>
   <array><string>/Users/dhiraj/.mydir/startup.sh</string></array>
   <key>RunAtLoad</key>
   <true/>
</dict>
</plist>

I have loaded it using below commond

sudo launchctl load -w ~/Library/LaunchAgents/com.example.exampld.plist

And also tested using

sudo launchctl start ~/Library/LaunchAgents/com.example.exampld.plist

But the shell script code is not executed i can say this because my shell script start a go build and open browser as below but nothing happens.

echo #start up go build#

    $HOME/.mydir/./go
    open http://localhost/sample/index.html
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
TechChain
  • 8,404
  • 29
  • 103
  • 228

1 Answers1

0

sudo launchctl load loads launchd agents/daemons in the local domain (/Library/..).

In the user domain you have to call launchctl without sudo

vadian
  • 274,689
  • 30
  • 353
  • 361