6

(There's plenty of questions about toggling Do Not Disturb programmatically, this is different)

Is there a plist file or sqlite DB that can be modified to change these settings programmatically? Specifically, "Show notifications on lock screen", "Show in Notification Center", etc.

I would like to change these in bulk, and sync those changes between my machines.

A screenshot of the macOS system settings, with the Notifications pref pane open, focused on the Mail app.

(I happen to be using the Venura Beta, but this question applies equally to Monteray).

I found NCUtil, but things have changed since it was written.

  • It expects there to be a SQLite DB at $(getconf DARWIN_USER_DIR)com.apple.notificationcenter/db/db,
  • but it's now at $(getconf DARWIN_USER_DIR)com.apple.notificationcenter/db/db, which has a different schema (e.g. there's no more app_info table with a flags column)

1 Answer 1

4

Yes, the file name is /Users/<username>/Library/Preferences/com.apple.ncprefs.plist you can modify flags value for your app in that file to "Show notifications on lock screen" or "Show in Notification Center".

The file is in plist binary format. You can convert it in xml format for obeserving the flag values. Use below command:

plutil -convert xml1 "/Users/<username>/Library/Preferences/com.apple.ncprefs.plist" 

Change the settings from System Preferences and observe the desired value and then set it programatically using PlistBuddy

Providing you sample code to forcefully turn on notifications for your app

#!/bin/sh notification_plist="/Users/$user/Library/Preferences/com.apple.ncprefs.plist" #Count of the bundles existing in the plist count=$(/usr/libexec/PlistBuddy -c "Print :apps" "${notification_plist}" | grep -c "bundle-id") for ((index=1; index<"${count}"; index++)); do bundle_id=$(/usr/libexec/PlistBuddy -c "Print apps:${index}:bundle-id" "${notification_plist}"); if [[ "${bundle_id}" == <your app bundle id> ]]; then flags_value=$(/usr/libexec/PlistBuddy -c "Print apps:${index}:flags" "${notification_plist}"); echo $flags_value $index if [[ $flags_value == 276* ]]; then /usr/libexec/PlistBuddy -c "Set :apps:${index}:flags 41951246" "${notification_plist}" fi fi done # Restart notification center to make changes take effect. killall sighup usernoted 

Note: You need to restart the usernoted service binary for changes to take effect, just kill it macOS will immediately start it again. The solution is tested on macOS Big Sur and Monterey.

7
  • Oh wow, this is great! Thanks for taking the time to write this up! Commented Sep 14, 2023 at 2:38
  • What is the significance of 41951246 and 276? What if I wanted to turn a notification off? Commented Oct 27, 2023 at 19:29
  • @Mike the number is a bitmask. For example 310386694 = 00010010100000000010000000000110. In macOS Sonoma the 7th bit (index 6) corresponds to ON/OFF. This example is ON. Commented Sep 27, 2024 at 19:30
  • @enriquejr99, that makes sense (thank you), but how would I know which bit to swap? Commented Sep 30, 2024 at 20:27
  • @Mike I don't think Apple has docs on that. However, you can change the notification settings of any app manually, and find which bit corresponds to that particular setting by inspecting how the bitmask changes. Commented Oct 1, 2024 at 18:24

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.