On OS X 10.8, users can disable Notification Center for a single day. Is there a way to check if it is enabled from the command line?.
5 Answers
You actually can find out if the Do Not Disturb is currently enabled or disabled. Notification Center drops a plist in the following location that you can read the value of. Run the following to find the plist file:
ls ~/Library/Preferences/ByHost/com.apple.notificationcenterui.*.plist
Now, you can read the value from the plist you just found by using:
defaults read ~/Library/Preferences/ByHost/com.apple.notificationcenterui.8D3EA20D-8D7F-52E2-9F99-BC17A13A3F0E.plist
NOTE: your actual filename may be different than what I have listed above.
You will see a key called "doNotDisturb" and it will either have a value of 1 or 0 (enabled or disabled)
You can also change it's status by doing:
defaults write ~/Library/Preferences/ByHost/com.apple.notificationcenterui.8D3EA20D-8D7F-52E2-9F99-BC17A13A3F0E.plist doNotDisturb 1
or:
defaults write ~/Library/Preferences/ByHost/com.apple.notificationcenterui.8D3EA20D-8D7F-52E2-9F99-BC17A13A3F0E.plist doNotDisturb 0
To make the change take effect, you'll need to restart Notification Center by typing:
killall NotificationCenter
I've actually written a very simple Automator script so now I can enable/disable the Do Not Disturb for Notification Center with a keyboard shortcut. Very handy. :)
-
Unfortunately, setting this on/off does not work on El Capitan. Commented Nov 27, 2015 at 23:22
-
-
This won't work. 1. this UUID is specific for you. 2.
killall NotificationCenter
will reset the settings to default but not reload the settings.– SimbaCommented Nov 7, 2019 at 17:26 -
To get the Do not disturb status in Yosemite, just enter the following in your terminal:
defaults read ~/Library/Preferences/ByHost/com.apple.notificationcenterui.plist doNotDisturb
-
1This is much better than the accepter answer IMO, as (1) you just copy and paste it and (2) in my system (MacOS Sierra) this works and the accepted solution doesn't (it says "domain does not exist", the file exists but it is empty). Therefore I really like this one. Commented Dec 16, 2020 at 9:53
-
2FWIW, does not work in Monterey (domain/default pair does not exist) Even if you manually find the plist (now in ~Library/Containers/com.apple.notificationcenterui/Data/Library/Preferences/com.apple.notificationcenterui.plist the default isn't found in it.– nmrCommented Nov 11, 2021 at 17:48
Setting of the Notification center is stored in the ~/Library/Preferences/ByHost
folder, which means it's a machine-specific settings.
You can use defaults -currentHost
command to read the settings within. -currentHost
is used to specify the ByHost
setting not the common user specific one stored in ~/Library/Preferences
.
defaults -currentHost read com.apple.notificationcenterui doNotDisturb
Output value 1
means it's activated, 0
for disabled.
In fact, the above command is reading options from ~/Library/Preferences/ByHost/com.apple.notificationcenterui.<your-UUID>.plist
file.
Caveats: Setting ByHost
options with defaults -currentHost write
doesn't work. The options are indeed written into the file, but it's not reloaded by the corresponding daemon. I guess this is a bug.
References
Probably the best way I can think of is to install terminal notifier and send it a message from the terminal.
Install Terminal Notifier
Terminal notifier can be installed through Ruby Gems
Type:
sudo gem install terminal-notifier
Send NC a message
Type:
terminal-notifier -message "The notification center is running" -title "NC Status"
If notification center is running you'll get a message that says "The notification center is running"
-
2The above worked well for me but it's a manual solution rather than a programmatic status indication so I'm not giving it a +1 as an answer to this question. It was however very useful in other respects. Commented Jun 29, 2014 at 20:41
-
Giving this an upvote is not the same as selecting the answer as correct. If the answer helped you but didn't answer the question you can give it an upvote. if it answered your question then click on the checkmark icon on the left side.– NatsfanCommented Nov 7, 2019 at 20:29
At the moment, the ways to interact with Notification Center programmatically (including via the command line) are pretty limited. As InfluenceJamie noted, there's terminal-notifier, which allows you to send notifications from the command line, but sending notifications is pretty much all programs can do at the moment. From my reading of the developer documentation, programs can only send and get information about the specific notifications they send, no status information for Notifcation Center itself, or other notifications. There's also no Applescript interface.
So at the moment, you're limited to manually testing whether a notification goes through, as InfluenceJamie suggested, or hoping that someone figures out Apple's private APIs and makes a command line interface.
-
In MacOS every preference is stored in some plist files, so there must be some "defaults read" stuff to do what I'm looking for. Commented Aug 5, 2012 at 22:54
-
1Well, that's a possibility of course, but the defaults are more for permanent preferences - a temporary setting might not be stored in the defaults. However that's probably your best bet if InfluenceJamie's suggestion doesn't work for you. Commented Aug 5, 2012 at 23:01
-