我想在 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