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?.
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:
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
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:
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. :)
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
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
sudo gem install terminal-notifier
Send NC a message
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"
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.
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
defaults -currentHost read com.apple.notificationcenterui doNotDisturb
1 means it's activated,
0 for disabled.
In fact, the above command is reading options from
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.