注:尚未实现,以下仅为操作记录

一、安装Homebrew
注:Homebrew 类似linux下的yum、apt等包管理软,这里要利用这个包管理软件安装sleepwatcher

1. 创建Homebrew要使用的目录

sudo mkdir /usr/local/Homebrew
sudo mkdir /usr/local/Cellar

2. 同步brew.git库
sudo git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git /usr/local/Homebrew

3. 添加替身(软链接)
sudo ln -s /usr/local/Homebrew/bin/brew /usr/local/bin/brew

4. 同步core库
sudo mkdir -p /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
sudo git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core

5. 同步cask
sudo mkdir -p /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
sudo git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask

6. 提权
sudo mkdir -p  /usr/local/var/homebrew/locks
sudo chown -R $(whoami) /usr/local/Homebrew
sudo chown -R $(whoami) /usr/local/Cellar
sudo chown -R $(whoami) /usr/local/var/homebrew

7. 查看版本号
brew -v

8.更换镜像源(提高下载速度)
cd "$(brew --repo)"
git remote set-url origin git://mirrors.ustc.edu.cn/brew.git

zsh用户:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc     #刷新

bash用户:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile   #刷新

9. 更新源
brew update


10. 建立一些需要的目录并授权
chmod u+w /usr/local/bin /usr/local/share
sudo chmod 777 /usr/local/bin
sudo chmod 777/usr/local/share
sudo mkdir -p /usr/local/Frameworks /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin
sudo chown -R $(whoami) /usr/local/Frameworks /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin

homebrew安装完成

二、安装sleepwatcher
brew install sleepwatcher
brew services start sleepwatcher
ps aux | grep sleepwatcher    #检查sleepwatcher进程是否已运行

三、配置sleepwatcher
touch ~/.wakeup    #唤醒时要执行的命令脚本
touch ~/.sleep        #睡眠时要执行的命令脚本
chmod u+x ~/.wakeup
chmod u+x ~/.sleep

四、验证sleepwatcher是否工作
1. 在~/.wakeup文件中写一条命令
vi  ~/.wakeup
======================
echo "a" >> ~/sleep.log
======================

2. 使电脑睡眠后再唤醒

3. 查看~/sleep.log文件内容
cat ~/sleep.log    #正常的话每睡眠唤醒后会多一行“a”

五、自动调整分辩率
在~/.wakeup中添加一行命令
=========================
source /usr/local/bin/disflick.sh
=========================
希望在唤醒后自动执行之前编本的用于解决闪屏问题的/usr/local/bin/disflick.sh脚本,该脚本的详情见:http://blog.chinaunix.net/uid-8204701-id-5837989.html
未能成功,待解决。有知道的朋友请留言告知,谢谢!

注:使用https://github.com/osy86/HaC-Mini/issues/7介绍的方法,经验证可以实现自动更改分辩率以解决闪屏问题。但此方法较为死板,如:分辩率为1080P的情况下,唤醒后会被自动改为2K。

参考资料:
1. 使用sleepwatcher在Mac唤醒时自启程序:https://my.oschina.net/lvyi/blog/1547856?utm_source=debugrun&utm_medium=referral
注:其中brew service start sleepwatcher存在错误,应是:brew services start sleepwatcher

2.Mac 电脑 利用Sleepwatcher和blueutil 实现电脑休眠自动关闭蓝牙,唤醒自动打开蓝牙:https://blog.csdn.net/qq944417919/article/details/84297806

3.Sleepwatcher:Mac睡眠与唤醒自动执行命令:https://blog.csdn.net/weixin_39505272/article/details/95911819?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.channel_param

4. https://github.com/osy86/HaC-Mini/issues/7

5.安装brew的正确姿势:https://www.cnblogs.com/huanhao/p/installbrew.html



09-11 17:45