NCutil icon indicating copy to clipboard operation
NCutil copied to clipboard

NCutil.py can cause Do Not Disturb to be unset

Open gregneagle opened this issue 9 years ago • 4 comments

Steps to reproduce:

In Mavericks: Set Do Not Disturb to On by pulling down the Notification Center from the menu bar Use an NCutil.py command that alters NC settings. Check the state of "Do Not Disturb" -- it's off again.

Yosemite does not seem to have this issue.

gregneagle avatar Apr 07 '15 17:04 gregneagle

This is triggered by the killall NotificationCenter that NCutil.py does after making a change. You can replicate the issue by turning on Do Not Disturb and then doing killall NotificationCenter.

This might not be fixable; at the very least a warning should be in the READ ME.

gregneagle avatar Apr 07 '15 17:04 gregneagle

I added it to the README. I wonder if we can just use the defaults to read and write the value to stay what it is.

defaults read $HOME/Library/Preferences/ByHost/com.apple.notificationcenterui.*.plist doNotDisturb

0 is returned if it is off 1 if it is enabled

but this also uses a unique ID. The command above just uses a * but the real .plist has a name like com.apple.notificationcenterui.030C2F1F-D406-F25E-75A7-1C6C1865DE3E.plist

I'm sure there is a way to do it via a Python library, but I'm not familiar enough for that. I would probably just make a call out similar to how it's done for the killall NotificationCenter command.

jacobsalmela avatar Apr 07 '15 22:04 jacobsalmela

One uses the -currentHost flag to read and write ByHost preferences:

defaults -currentHost read com.apple.notificationcenterui

There are CFPreferences methods that can be called from Python to the same effect.

But being able to read/write this preference is not sufficient -- in Mavericks, the value there is never updated to match the UI (at least in my testing).

gregneagle avatar Apr 07 '15 22:04 gregneagle

In Mavericks:

% defaults -currentHost read com.apple.notificationcenterui
{
    doNotDisturb = 0;
    doNotDisturbMirrored = 1;
}

Now I pull down the Notification Center menu and enable Do Not Disturb. Then:

% defaults -currentHost read com.apple.notificationcenterui
{
    doNotDisturb = 0;
    doNotDisturbMirrored = 1;
}

No change. Values change as hoped/expected in Mountain Lion and Yosemite...

gregneagle avatar Apr 07 '15 22:04 gregneagle