• MacOS通过命令行开启关闭向日葵远程控制的后台服务



    categories: [Tips]
    tags: MacOS Tips

    写在前面

    经常有小伙伴问我电脑相关的问题, 而解决问题的一个重要途径就是远程了. 关于免费的远程工具我试过向日葵和 todesk, 并且主要使用向日葵, 虽然 MacOS 下要设置很多权限, 但是也不影响其丝滑的控制.

    虽然用着舒服, 但是向日葵美中不足的一点就是后台服务的内存占用, 对我这种强迫症还是接受不了, 后来想到的办法是在系统设置里面的 通用-> 登录项允许在后台执行的程序, 可以打开或者关闭向日葵的服务. 但是每次开关都麻烦, 所以就自然想到通过命令行来操作了.

    向日葵的后台服务

    Screenshot 2024-04-18 at 21.18.32

    可以看到向日葵的后台服务有4个, 通过查找

    • /Library/LaunchAgents
    • /Library/LaunchDaemons

    发现, 有以下4个文件:

    1. /Library/LaunchDaemons/com.oray.sunlogin.plist
    2. /Library/LaunchDaemons/com.oray.sunlogin.helper.plist
    3. /Library/LaunchAgents/com.oray.sunlogin.startup.plist
    4. /Library/LaunchAgents/com.oray.sunlogin.agent.plist

    总不能一个一个设置吧, 后来看了篇文章讲 Apple 里面的后台进程可以通过 sudo launchctl list 来查看.

    找到关键的后台服务

    从设置里面打开向日葵的后台服务, 执行

    sudo launchctl list |grep oray
    
    42070	0	com.oray.sunlogin.helper
    42081	0	com.oray.sunlogin.service
    
    • 1
    • 2
    • 3
    • 4

    多了俩服务, 那么接着分析, 看 plist 文件发现其实主要是 /Library/LaunchDaemons/com.oray.sunlogin.helper.plist 这个文件, 那么接下来就好办了.

    开启/关闭后台服务

    # 开启
    sudo launchctl load -wF /Library/LaunchDaemons/com.oray.sunlogin.helper.plist
    # 关闭
    sudo launchctl unload -wF /Library/LaunchDaemons/com.oray.sunlogin.helper.plist
    
    • 1
    • 2
    • 3
    • 4

    可以用 alias封装一下, 这样直接通过命令行启动/关闭向日葵即可.

    命令行开启关闭向日葵

    alias sunlogin='sudo launchctl load -wF /Library/LaunchDaemons/com.oray.sunlogin.helper.plist && open -a SunloginClient.app'
    
    alias sunlogout='sudo pkill SunloginClient && sudo launchctl unload -wF /Library/LaunchDaemons/com.oray.sunlogin.helper.plist && sudo launchctl unload -wF /Library/LaunchDaemons/com.oray.sunlogin.plist'
    
    • 1
    • 2
    • 3
  • 相关阅读:
    嵌入式 单片机面试 通信协议常见问题答案 串口通信 IIC通信 SPI通信 协议解析讲解 RS232 RS485 协议 IIC总线
    python--requests接口测试
    测试应届生是去自研小公司好还是外包公司好?
    2023牛客OI赛前集训营-提高组(第二场) 集合
    【Redis】主从复制
    net core 反射获取泛型-泛型方法method<T>(T t1)
    Shell脚本<<eeooff的使用
    浅谈中国程序员的四个层次,你在第几层?
    mysql日常优化的总结
    力扣刷题(代码回忆录)——链表部分
  • 原文地址:https://blog.csdn.net/qq_41437512/article/details/138199413