13

For nuisance apps that set a badge notification icon, but which are not in the Settings Notifications center, is there a way to block the badge icon?


Spotify, for example, creates a notification for every insignificant event, with no way of blocking it in app.

Personally I don't understand how apps are allowed to show a badge icon without being in the Notifications center in the first place.


Example:

enter image description here

3

2 Answers 2

27

Newer versions of MacOS

The following script has been developed by Dylan Gattery

# "Usernoted" seems to be the "user notifications daemon", so get it's PID.
pid=$(ps -A | grep -m1 usernoted | awk '{print $1}')

# Find the sqlite3 database that this program has open. It's in a "private" folder (app sandboxing).
db="$(lsof -p $pid | grep 'com.apple.notificationcenter/db2/db$' | awk '{print $9}')"

# I got the bundleid from Spotify.app/Contents/Info.plist
bundleid="com.spotify.client"

# This is the database modification to make.
sql="INSERT INTO app (identifier, badge) VALUES ( '$bundleid', 0 );"

# Run the command
sqlite3 "$db" "$sql"

# Restart Dock and usernoted to make the changes take effect
killall usernoted
killall Dock

This should cause the badge to immediately disappear, and the program should be listed in the system preferences pane.

Original answer (tested on Yosemite)

I have a solution that I was able to reverse engineer. I've tested it on my machine, running Yosemite 10.10.4 (14E46). If you can find the bundle ID (in the Info.plist file for the app bundle), you can use this script to force the app to appear in the notifications preferences pane.

# "Usernoted" seems to be the "user notifications daemon", so get it's PID.
pid=$(ps aux | grep -i [u]sernoted | awk '{print $2}')

# Find the sqlite3 database that this program has open. It's in a "private" folder (app sandboxing).
db="$(lsof -p $pid | grep com.apple.notificationcenter/db/db\$ | awk '{print $9}')"

# I got the bundleid from Spotify.app/Contents/Info.plist
bundleid="com.spotify.client"

# I use 0 as the flags because you can change all the settings in System Preferences
# 5 seems to be the default for show_count
# Grab the next-highest sort order
sql="INSERT INTO app_info (bundleid, flags, show_count, sort_order) VALUES ( '$bundleid', 0, 5, (SELECT MAX(sort_order) + 1 FROM app_info) );"

# Run the command
sqlite3 "$db" "$sql"

# Restart usernoted to make the changes take effect
killall usernoted

At this point you can open System Preferences -> Notifications, and you will find the app that you just added at the bottom of the list. You can enable / disable badging the icon from this page.

7
  • 2
    Cool trick! For me it was only working with pid=$(ps -A | grep -m1 usernoted | awk '{print $1}') as the original command was showing two PID's instead of one.
    – MegaCookie
    Jul 15, 2016 at 13:10
  • 3
    Need to replace grep com.apple.notificationcenter/db/db\$ with grep 'com.apple.notificationcenter/db2/db$' as of Mac OS 10.14.1 (possibly before, I see this is over 3 years old already)
    – Alex S
    Nov 22, 2018 at 18:12
  • 1
    AND of course with this new db2 format, adding the app to the database does NOT make it show up in the notification preferences 😞
    – Alex S
    Nov 22, 2018 at 18:28
  • 1
    I haven't tried, but I want to confirm you modified your SQL for the new format, right? I'm guessing you need INSERT INTO app (identifier, badge, app_id) VALUES ( '$bundleid', 0, (SELECT MAX(app_id) + 1 FROM app) ); Nov 23, 2018 at 19:34
  • 1
    Update for 2022/macOS 13: pid=$(ps -A | grep -m1 usernoted | awk '{print $1}') works, grep com.apple.notificationcenter/db/db\$ with grep 'com.apple.notificationcenter/db2/db$' works, but then the sql has to change significantly. Here's what I reverse engineered - the table name changed, as did the schema: sql="INSERT INTO app (identifier, badge) VALUES ( '$bundleid', 0 );" I also had to killall Dock to get rid of the badge Nov 21, 2022 at 2:42
0

For those people who are mac noobs like me, to create and run the above script:

1. Open TextEdit,
2. Put the editor into Plain Text mode - Format > Make Plain Text.
(If you skip this step, it will not let you save it as a script.)
3. Paste the above script into the TextEdit window
4. Save the file as a script - File > Save As in TextEdit. Enter your filename followed by the “.sh” file extension, and then Save the document to the Desktop.
5. Open the Terminal application
6. Navigate to the desktop in Terminal - Type in (then press enter):

cd Desktop
7. Set the permissions for the file you just created so you can run it - Type in Terminal (then press en):
sudo chmod 700 file.sh
(Replace "file.sh" with the name of your script.)
8. Run the file - Type in Terminal:
./file.sh
(Again, replace "file.sh" with the name of your script.)
9. Open Notifications in System Preferences. You should be able to find the Spotify App and turn off the notifications.

Source for creating a script: Terminal 101: Automate the Terminal with Bash Scripts

1
  • 1
    Good tutorial on making an executable shell script, but for the upvoted solution you don't need a bash script. Just open terminal and paste in the commands. Skip lines that begin with a #, because that is a comment in bash. May 27, 2016 at 20:30

You must log in to answer this question.

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