macos launchd plist
~/Library/LaunchAgents/com.example.myapp.plist:
<?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">
  <!-- https://superuser.com/a/229792 -->
  <!-- https://opensource.apple.com/source/launchd/launchd-257/launchd/doc/HOWTO.html -->
  <!-- https://launched.zerowidth.com/ -->
  <dict>
    <key>Label</key>
    <string>com.example.myapp</string>
    <key>UserName</key>
    <string>handsome</string>
    <key>WorkingDirectory</key>
    <string>/Users/handsome/dev/myapp/</string>
    <key>ProgramArguments</key>
    <array>
        <string>./myexe</string>
        <string>arg1</string>
        <string>arg2</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <dict>
      <key>Crashed</key>
      <true/>
    </dict>
  </dict>
</plist>
加入启动项
launchctl load ~/Library/LaunchAgents/com.example.myapp.plist
启动
launchctl start com.example.myapp
移除启动项
launchctl remove com.example.myapp
查看帮助
launchctl
note
放在 ~/Library/LaunchAgents/ 目录下的 plist 文件是在你开机之后,输入密码登录进操作系统后,才会启动的
如果想要在登录之前就启动,则需要放在 /Library/LaunchDaemons/ 下
    +V why_null 请备注:from博客园
                    
                
                
            
        
浙公网安备 33010602011771号