Disabling "Show notifications on lock screen" in system prefs

kaci_weirich
New Contributor

I am brainstorming a good way to disable "Show notifications on lock screen" in the notifications section of System Preferences. I would like users to be able to get general notifications if they choose, just not on lock screen. What suggestions do you have? Has anyone had success disabling this specific feature of Notifications?

13 REPLIES 13

jrserapio
Contributor

I would like a solution to this as well. My colleague has been digging and it looks like all the notification preferences are being written to a local sqlite db. I would love to get a solution to this.

matt4836
Contributor II

You can do this with the script I wrote in this thread:

Another Discussion

Jason
Contributor II

@matt4836 That's a great script. I'm planning on using it shortly. If i'd like to set certain actions for multiple applications like COM.APPLE.MAIL and COM.APPLE.ICHAT would that require both commands below to be run, or can it be combined into a single command? I don't want to do this for all Apple applications which is why "-e Apple" would not work for me.

modifyNotificationCenter.py -e COM.APPLE.MAIL -C -A -B -S
modifyNotificationCenter.py -e COM.APPLE.ICHAT -C -A -B -S

Thanks!

matt4836
Contributor II

That is correct.

lsegura
New Contributor II

Hi @matt4836 I was checking your script and I tried to use it in Sierra but it does not work. Do you have any other script that I can use for Sierra in order to disable the notification on lock screen? I would appreciate any help.

Asnyder
Contributor III

@Jason you could do COM.APPLE.* I think

EDIT: I misread this and thought you wanted it for all com.apple. My mistake.

prl
Contributor

any update on this for Mojave machines? trying to disable lock screen notifications in Mojave for Slack via Jamf Pro. Would likely deploy it to all apps in the long run.

jmariani
Contributor

I've had success with the following script. This seems to work on the first run only. The flag value is a bit different on 10.14 and if the user re-enables the notification, the script might not work as expected the second run. YMMV.

#!/bin/sh
#Populating variables for OS Major and Minor Version
osvers_major=$(sw_vers -productVersion | awk -F. '{print $1}')
osvers_minor=$(sw_vers -productVersion | awk -F. '{print $2}')

IFS=$'
'

user=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");')

#Location of the notification center preferences plist for the current user
notificationsPLIST="/Users/$user/Library/Preferences/com.apple.ncprefs.plist"

#List of the name of the bundles that need to be configured. Set to your needs.
#bundlesToConfigure=('com.apple.FaceTime' 'com.apple.iCal' 'com.apple.FaceTime' 'com.apple.gamecenter' 'com.apple.mail' 'com.apple.iChat' 'com.apple.reminders' 'com.apple.Safari' 'com.apple.iTunes')
# Get list of all user manipulatable notification center objects 
bundlesToConfigure=`defaults read $notificationsPLIST  | grep bundle-id | awk -F " '{print $4}' | grep -v "_SYSTEM_CENTER_"` 

#Count of the bundles existing in the plist
apps=`/usr/libexec/PlistBuddy -c "Print :apps" "$notificationsPLIST"`
count=$(echo "$apps" | grep "bundle-id"|wc -l)

#Substracting one to run in a for loop
count=$((count - 1))
change=0

disableNotifcationNonMojave() 
{
for index in $(seq 0 $count); do
    #Getting each bundle id with PlistBuddy
    bundleID=$(/usr/libexec/PlistBuddy -c "Print apps:$index:bundle-id" "$notificationsPLIST");
    #If the name of the current bundle is in our list of bundles to configure
    if [[ "${bundlesToConfigure[*]}" == *"$bundleID"* ]]; then
        flag=`/usr/libexec/PlistBuddy -c "Print apps:$index:flags" "$notificationsPLIST"`
        echo Current value:  $index:$bundleID $flag
        if [ $flag -lt 4096 ]; then
            echo "  Flag is less than 4096.  Adding 4096 to disable notification/preview on lockscreen."
            flag=$((flag + 4096))
            change=1
            sudo -u $user /usr/libexec/PlistBuddy -c "Set :apps:${index}:flags ${flag}" "$notificationsPLIST"
            flag=`/usr/libexec/PlistBuddy -c "Print apps:$index:flags" "$notificationsPLIST"`
            echo New Value: $index:$bundleID $flag
        fi
    fi
done
}

disableNotifcationMojave()
{
for index in $(seq 0 $count); do
    #Getting each bundle id with PlistBuddy
    bundleID=$(/usr/libexec/PlistBuddy -c "Print apps:$index:bundle-id" "$notificationsPLIST");
    #If the name of the current bundle is in our list of bundles to configure
    if [[ "${bundlesToConfigure[*]}" == *"$bundleID"* ]]; then
        flag=`/usr/libexec/PlistBuddy -c "Print apps:$index:flags" "$notificationsPLIST"`
        echo Current value:  $index:$bundleID $flag
        if [ $flag -lt 12438 ]; then
            echo "  Flag is less than 12438.  Adding 4096 to disable notification/preview on lockscreen."
            flag=$((flag + 4096))
            change=1
            sudo -u $user /usr/libexec/PlistBuddy -c "Set :apps:${index}:flags ${flag}" "$notificationsPLIST"
            flag=`/usr/libexec/PlistBuddy -c "Print apps:$index:flags" "$notificationsPLIST"`
            echo New Value: $index:$bundleID $flag
        fi
    fi
done
}

if [[ ${osvers_major} -eq 10 ]] && [[ ${osvers_minor} -ge 14 ]]; then
    echo "${osvers_major}.${osvers_minor} Mojave was detected. Applying appropriate values."
    disableNotifcationMojave
else
    echo "${osvers_major}.${osvers_minor} Non-Mojave was detected. Applying appropriate values."
    disableNotifcationNonMojave
fi

# Restart notification center to make changes take effect.
if [ $change == 1 ]; then echo "Changes made.  Restarting Notification Center for them to take effect.";killall sighup usernoted;killall sighup NotificationCenter; fi

exit 0

rmorse
New Contributor II

@jmariani awesome work on the script!

I've been playing around with it's close doing doing what I need. I was hoping to modify it to just uncheck "Show notifications on lock screen" instead of unchecking "Show notification preview". The different flag numbers don't make this a simple task. Any advise?

tony_t
New Contributor

@jmariani thanks for your script, I changed it i bit to better reflect the flag comparison. I now dont have any issues for first or second run.

...
disableNotifcationMojave()
{
for index in $(seq 0 $count); do

#Getting each bundle id with PlistBuddy

bundleID=$(/usr/libexec/PlistBuddy -c "Print apps:$index:bundle-id" "$notificationsPLIST");

#If the name of the current bundle is in our list of bundles to configure

if [[ "${bundlesToConfigure[]}" == "$bundleID"* ]]; then

flag=/usr/libexec/PlistBuddy -c "Print apps:$index:flags" "$notificationsPLIST"

logger DN Current value: $index:$bundleID $flag

flag1=$(($flag & 4096))

echo $flag1

if [ $flag1 == 0 ]; then

logger DN Flag is on. Adding 4096 to disable notification/preview on lockscreen.

flag=$((flag | 4096))

change=1

sudo -u $user /usr/libexec/PlistBuddy -c "Set :apps:${index}:flags ${flag}" "$notificationsPLIST"

flag=/usr/libexec/PlistBuddy -c "Print apps:$index:flags" "$notificationsPLIST"

logger New Value: $index:$bundleID $flag

fi

fi
done
}

tony_t
New Contributor

.

tony_t
New Contributor

.

captam3rica
New Contributor III

In case anyone is still looking for a solution to managing macOS notifications outside of a configuration profile check out this GitHub project ncprefs.py. Initial testing looks promising. The only caveat is whether or not you would like to maintain the python dependencies. (hint: there is a solution for this - github.com/macadmins/python)