我如何在我的终端中发出一个shell命令,一旦一个给定的时间过去了,它就会用通知通知我?
为了说得更具体一点,我要找的是:
remindme "3 hours" "see if thing x has finished yet"的事情,而不必做太多复杂的shell魔术。如果失败了,如果它至少可以被一个脚本包装,那就更好了。task next之前我不会看到这些任务。checkreminders命令,那么启动一个新的shell并查看通知可能需要很长时间。像alias ls=checkreminders && ls这样的东西也是如此。发布于 2021-09-03 08:09:27
Usage: remindme -t "3m 1s" -m "I have to do homework"时间可以是简单的数字表示第二,或有后缀s,m,h或d。参阅手册页的GNU睡眠。对于macOS,您需要将时间转换为秒,或者编写一个函数来这样做。
解决方案1:使用墙壁。在Linux上工作,无论是图形化的还是非图形化的,都应该在macOS上工作,至少是非图形化的.
#!/bin/bash
while getopts "t:m:" optname; do
case $optname in
t)
time=${OPTARG}
;;
m)
message=${OPTARG}
;;
esac
done
coproc (sleep $time && wall $message)解决方案2.1:用于Linux和Windows的桌面通知,需要libnotify提供的D3
#!/bin/bash
while getopts "t:m:" optname; do
case $optname in
t)
time=${OPTARG}
;;
m)
message=${OPTARG}
;;
esac
done
coproc (sleep $time && notify-send -a Reminder "$message")解决方案2.2: macOS的桌面通知。还没测试过。
#!/bin/bash
while getopts "t:m:" optname; do
case $optname in
t)
time=${OPTARG}
;;
m)
message=${OPTARG}
;;
esac
done
coproc (sleep $time && osascript -e 'display notification "$message" with title "Remainder"')https://softwarerecs.stackexchange.com/questions/80338
复制相似问题