Mac OS延迟通知脚本

工作中经常被IM的消息淹没,而且通常是优先级很低的事情,导致很难专注做事情,长期开勿扰模式又会导致一些事情漏掉。
这里提供一个小脚本,在系统中将勿扰模式(D)和通知中心(N)的快捷键设置好后,脚本会每半小时关闭5分钟勿扰模式来让你进行消息回复。

repeat while true
	ignoring application responses
		tell application "System Events" to keystroke "D" using {command down, shift down, option down, control down}
	end ignoring
	say "DND opened"
	delay 1800
	
	ignoring application responses
		tell application "System Events" to keystroke "D" using {command down, shift down, option down, control down}
	end ignoring
	ignoring application responses
		tell application "System Events" to keystroke "N" using {command down, shift down, option down, control down}
	end ignoring
	say "DND closed"
	delay 300
end repeat