0

我想在 mac 启动时运行一个 shell 脚本。为此,我创建了一个 shell 脚本和 plist 文件。我已将 plist 复制到 ~/Library/LaunchAgents/com.example.exampld.plist. 它具有所有必需的权限。

<?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>

我已经使用下面的 commond 加载了它

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

并且还使用了测试

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

但是没有执行 shell 脚本代码我可以这样说,因为我的 shell 脚本启动了一个 go build 并打开浏览器,如下所示,但没有任何反应。

echo #start up go build#

    $HOME/.mydir/./go
    open http://localhost/sample/index.html
4

1 回答 1

0

sudo launchctl load在本地域( /Library/..)中加载已启动的代理程序/守护程序。

用户launchctl域中,您必须调用sudo

于 2019-03-26T10:11:38.773 回答