mac上定时提醒常喝水、多注意休息

Linux的定时功能crontab同样在macos上也可以用。

起因是之前检查过有尿结石,最近小腹疼,还尿出血,感觉又有结石了,所以还是要多喝水,所以写个定时提醒来时刻提醒自己。

先写段shell脚本来设置提醒内容
文件命令为 drink.sh

title="日常提醒"
content="常喝水,常排尿,远离疾病, 爱你的亲"
subtitle="记得喝水"
sound="Pon"
cmd=$(printf 'display notification "%s" with title "%s" subtitle "%s" sound name "%s"' "$content" "$title" "$subtitle" "$sound")
osascript -e "$cmd" 
say -v Ting-ting $content 

将drink.sh chmod加上x执行权限
关于display命令和osascript命令可以看上一篇介绍。
上面代码中 say -v的后面跟的语音角色,可以在设置>辅助>语音>系统语音>自定义中添加。我系统默认用的英文,加这个是用中文普通话朗读。

再来写个写时脚本,命名为drink.crontab

*/10 8-22 * * * /Users/hijack/Documents/Scripts/drink.sh

上面脚本意思是每天8点到22点每隔10分钟执行后面的脚本,就是上面的代码,用来显示通知和播放声音。
关于crontab的参数:

* * * * * command to execute
│ │ │ │ │
│ │ │ │ └─── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
│ │ │ └──────── month (1 - 12)
│ │ └───────────── day of month (1 - 31)
│ └────────────────── hour (0 - 23)
└─────────────────────── min (0 - 59)

好了,来添加到crontab中
crontab drink.crontab
来检查下是否加进去
crontab -l