Mac脚本自启动后台运行

方法一:

  1. creat xxx.xxx.xxx.plist

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    <?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">
    <dict>
    <key>Label</key>
    <string>xxx.xxx.xxx</string>
    <key>ProgramArguments</key>
    <array>
    <string>command</string>
    <string>parameter1</string>
    <string>parameter2</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    </dict>
    </plist>

    if you want to know the meanings of the items in the plist, please run man launchd & man launchd.plist

  2. add the plist file to /Library/LaunchAgents/ or ~/Library/LaunchAgents/
  3. sudo launchctl load /Library/LaunchAgents/xxx.xxx.xxx.plist

方法二:

  1. creat xxx.xxx.xxx.plist
  2. Install lunchy:gem install lunchy
  3. lunchy install /Library/LaunchAgents/xxx.xxx.xxx.plist
  4. lunchy start xxx.xxx.xxx.plist

方法三:

use the app Lingon
Lingon 1.2 is free, but some items of it are outdated
Lingon X 2.0 is not free.
Lingon 3 is in Mac APP Store, $10.