# 通知パネルの「閉じる」クリックをショートカットキーで行う方法 URL: https://webrandum.net/keyboard-maestro-notification-close/ 公開日: 2019-07-17 更新日: 2019-07-17 カテゴリー: 作業効率化 タグ: Keyboard Maestro, 通知 出典: Webrandum(著者: サイトウ マサカズ) システム環境設定の[通知]から通知の設定を「通知パネル」にしていると、「閉じる」をクリックするまで通知が消えません。 ![通知パネル](https://webrandum.net/mskz/wp-content/uploads/2019/07/image_2-10.png) 今回はこの通知パネルの「閉じる」をショートカットキーで押す方法についてです。 ## 通知を閉じるAppleScript 色々と調べていると、[下記のページ](http://www.genuinecuriosity.com/genuinecuriosity/2016/6/5/clear-away-multiple-os-x-alerts-with-a-keystroke)を見つけました。 [![](https://www.google.com/s2/favicons?domain=www.genuinecuriosity.com)Genuine Curiosity![](//webrandum.net/mskz/wp-content/uploads/pz-linkcard/cache/11df823f3804871441fe3b9e1593d513d77e016178e20df7e12f12d35bee9435.webp)Close Multiple OS X Alerts With One Shortcuthttp://www.genuinecuriosity.com/genuinecuriosity/2016/6/5/clear-away-multiple-os-x-alerts-with-a-keystrokeIf you're like me, sometimes you come back to your Mac screen and find a bunch of alerts hanging around on the screen - a collection of items ranging from "you didn't eject this disk properly!" warnings to calendar alerts, or alerts from other applications. Look familiar? I know these ale](http://www.genuinecuriosity.com/genuinecuriosity/2016/6/5/clear-away-multiple-os-x-alerts-with-a-keystroke) このページによると、下記のようなAppleScriptを書くと通知パネルを閉じれるとされています。 ``` そのままだとエラーmy closeNotif() on closeNotif() tell application "System Events" tell process "Notification Center" set theWindows to every window repeat with i from 1 to number of items in theWindows set this_item to item i of theWindows try click button 1 of this_item on error my closeNotif() end try end repeat end tell end tell end closeNotif ``` ただ、この通りに書いてもうまくいきません。 3行目にある”Notification Center”の部分は、どうやら半角スペースがいらないらしく、逆に半角スペースが入っているとエラーとなって動かなくなってしまいます。 正しくは下記のコードになります。 ``` 修正済みコードmy closeNotif() on closeNotif() tell application "System Events" tell process "NotificationCenter" set theWindows to every window repeat with i from 1 to number of items in theWindows set this_item to item i of theWindows try click button 1 of this_item on error my closeNotif() end try end repeat end tell end tell end closeNotif ``` ## Keyboard Maestroのマクロにする Keyboard Maestroで「Execute an AppleScript」アクションを設定して先ほどのコードを入力すればOKです。 ![通知を閉じるマクロ](https://webrandum.net/mskz/wp-content/uploads/2019/07/image_1-14-1024x829.png) 自分の場合はcommand + option + 0で発火するように設定しています。 通知を使っている人であれば、わざわざマウスを端っこへ移動させる必要がなくなるので地味に便利です。