2

I've been trying to create a script to disable/enable the Notification Center, even if it's temporary. It should do the same as manually sliding the Notification Center, scrolling up, and toggling the "Show Alerts and Banner" badge.

Anyone knows if it's posible and how to do it? :)

Thanks!

5

To disable Notification Center from the command line, write a KeepAlive key that is false into the /System/Library/LaunchAgents/com.apple.notificationcenterui.plist like so:

sudo defaults write /System/Library/LaunchAgents/com.apple.notificationcenterui KeepAlive -bool false  

If you want to re-enable Notification Center, you’d just run the same with a true:

sudo defaults write /System/Library/LaunchAgents/com.apple.notificationcenterui KeepAlive -bool true  

Method to DISABLE without sudo:

launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist  
killall NotificationCenter

Method to ENABLE without sudo:

launchctl load -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist  

Then just hit Command+Shift+G and go to /System/Library/CoreServices/ then find “Notification Center” and double-click it to launch it again

Tutorial with useful info here and here

  • it doesn't seem to work. I tried setting it to false and then triggering a notification through terminal-notifier, and it pops right in, with keelalive false and true. Do I need to do anything else? On the other hand, any chance on not doing it with sudo? Thanks! – Ramiro Araujo Apr 6 '13 at 3:36
  • 1
    Added method without sudo. If it's still not working for you please give me code-error return in terminal. – MnO Apr 6 '13 at 11:40
1

I just simply alt-click on the menubar icon, which actually greys it out and disables it until clicked on again.

  • 3
    Didn't know that, thanks. The question asks for a commandline solution though. – nohillside May 30 '13 at 5:13
0

Just came across this question 4 years later looking for the same thing and came up with this AppleScript that will toggle the enabled state of Notification Center:

    (*
    Toggle enabled state of Notification Center menu item
    Notification Center can be enabled/disabled by clicking the menu item with the Option key pressed.
    *)

    tell application "System Events"
        set ncMenu to menu bar 2 of application process "SystemUIServer"
        set ncItem to menu bar item 1 of ncMenu
        set ncTitle to title of ncItem

        set ncTitleEnabled to "Notification Center"
        set ncTitleDisabled to "Notification Center, Do Not Disturb enabled"

        if (ncTitle = ncTitleEnabled or ncTitle = ncTitleDisabled) then
            -- toggle enabled state of Notification Center
            key down {option}
            click menu bar item ncTitle of ncMenu
            key up {option}
        else
            -- can't access Notification Center menu
            display dialog "Notification Center is not available." with title "Applescript Error" buttons {"OK"} default button "OK"
        end if
    end tell

Save it as nc.scpt and run it in the terminal by creating an alias in your bash ~/.profile:

alias nc="osascript ~/path/to/nc.scpt"

Since OS X Mavericks you may get an error about osascript needing permission for "accessibility features". You'll need to add Terminal to the list of apps allowed to control your computer (System Preferences > Security & Privacy > Privacy > Accessibility). Since this allows any terminal script access to the GUI it may be better to convert the script to an Automator app and only grant this privilege to your app.

You can create a keyboard shortcut for the Automator app. See How to quickly jump to another application without using command tab. BTW I got the innards of the Notification Center menu with UI Browser (free trial).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .