[Mac][Keyboard Maestro] おやすみモードの状態を表示する
Mac のおやすみモード(Do Not Disturb)がオンになっているかオフになっているかを表示したい。最初は以下のアプリを使おうと思った。
Command Center | Cindori
https://cindori.org/commandcenter/
しかし、有料なのでなんとか自分で作れないか考えてみたところ、Keyboard Maestro を使えばできることが分かった。
シェルスクリプトは以下のようになる。
if [ -e "$HOME/.path" ]
then
source "$HOME/.path"
else
PATH=/usr/local/scripts:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
fi
#####
OSX_DND_RAW=`defaults -currentHost read "$HOME/Library/Preferences/ByHost/com.apple.notificationcenterui" doNotDisturb 2>/dev/null`
if [[ "$OSX_DND_RAW" = "1" ]]
then
IS_OSX_DND='yes'
else
IS_OSX_DND='no'
fi
#####
if [ "$IS_OSX_DND" = 'yes' ]
then
echo "DND mode"
elif [ "$IS_OSX_DND" = 'no' ]
then
echo "Notification mode."
fi
# EXIT = 1 means that something is NOT paused
# EXIT = 0 means that both ARE paused
exit 1
#
#EOF
シェルスクリプトの結果を一旦変数に書き出しているのは、後々いろいろマクロを拡張できるようにしているから。
参考:
“DND Macros” – Toggle (or check status of) Growl and OS X Notifications (and mute/unmute) – macro – Keyboard Maestro Discourse
https://forum.keyboardmaestro.com/t/dnd-macros-toggle-or-check-status-of-growl-and-os-x-notifications-and-mute-unmute/2260
Recent Posts
Archives