Skip to content

Instantly share code, notes, and snippets.

@hemisu
Created February 9, 2020 07:45
Show Gist options
  • Select an option

  • Save hemisu/5fb2a30e41eae6da62153842f4e21092 to your computer and use it in GitHub Desktop.

Select an option

Save hemisu/5fb2a30e41eae6da62153842f4e21092 to your computer and use it in GitHub Desktop.

Revisions

  1. hemisu created this gist Feb 9, 2020.
    41 changes: 41 additions & 0 deletions v2ray LaunchAgents.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    # mac配置v2ray命令行开机自启动

    参考文档: [CreatingLaunchdJobs](https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html)

    ## 编写plist文件
    例子中用户名为`name``【】`需要删除

    com.name.v2ray
    ```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">
    <dict>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>com.name.v2ray【推荐与文件名一致】</string>
    <key>Program</key>
    <string>/Users/name/v2ray【修改为命令行路径】</string>
    <key>RunAtLoad</key>
    <true/>
    <key>UserName</key>
    <string>修改为你的用户名</string>
    </dict>
    </plist>
    ```

    ## 第二部,加入自启动项
    - 检查
    在复制文件之前,使用命令检查一下,文件是否正确 `plutil com.name.v2ray.plist`
    - 复制
    把刚才编写好的plist文件复制到 `~/Library/LaunchAgents/` 目录中去,使用命令 `cp com.name.v2ray.plist ~/Library/LaunchAgents/`
    - 加载
    加载plist文件 `launchctl load ~/Library/LaunchAgents/com.name.v2ray.plist`
    - 确认
    确认文件是否被加载,执行命令 `launchctl list | grep com.name`

    ## 第三步,重启确认
    - 重启系统查看是否生效
    - 删除自启动项
    如果需要删除,执行命令 `launchctl unload ~/Library/LaunchAgents/com.name.v2ray.plist`