mac自启动、唤醒启动

23 篇文章 0 订阅

简单开机启动
- 系统偏好设置->帐户->登陆项
- 执行程序启动目录
/System/Library/StartupItems
/Library/StartupItems/

可设置开机启动、唤醒启动
- 用户未登陆前就启动
/Library/LaunchDaemons
/System/Library/LaunchDaemons
- 用户登陆后启动
~/Library/LaunchAgents
/Library/LaunchAgents
/System/Library/LaunchAgents

唤醒时通常会重连wifi,而同时SystemConfiguration目录的内容会发生变化,从而触发sh文件

cd ~/Library/LaunchAgents 

File: df.plist
在开机或者唤醒(wifi连接状态发生变化)时会触发

<?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>df</string>
                <key>Program</key>
                <string>/Users/df/wake.sh</string>
         <key>WatchPaths</key>
        <array>
                <string>/Library/Preferences/SystemConfiguration</string>
        </array>
<key>WorkingDirectory</key>
    <string>/Users/df/</string>
                <key>RunAtLoad</key>
        <true/>
        </dict>
        </plist>

将文件设为可直接执行,将文件“显示简介”里的打开方式设置为shell

sudo chmod +x wake.sh

管理启动服务

launchctl load ~/Library/LaunchAgents/df.plist
launchctl start df


launchctl unload ~/Library/LaunchAgents/df.plist
launchctl stop df

  • 卸载启动程序用rm是没用的,应该用“launchctl unload”
  • 更改plist内容之后需要重新装载文件才能生效
  • plist加载的程序会在后台运行,在前台是看不到的



关闭自启动程序

launchctl unload ~/Library/LaunchAgents/df.plist

常用的自启动目录

~/Library/LaunchAgents 
/Library/LaunchAgents 

禁用自启动程序

  • cd ~/Library/LaunchAgents
  • ls
  • open org.getlantern.plist #用xcode打开org.getlantern.plist
  • RunAtLoad —— No #禁止自启动
  • cd /Library/LaunchAgents
  • ls
  • rm xx.plist #此目录无法修改RunAtLoad参数,只能删除
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值