Disabling Notifications for Student Macbooks with Ventura+

pbileci
Contributor

We are going all online for the ACT this year and we have to use Pearson's TestNav app in order for the students to test on their school-issued Macbook Airs. They are running MacOS Ventura (or Sonoma for those who upgraded before we had the chance to block updates).The TestNav documentation says that we need to disable all of the notifications for the students while they're taking tests. I haven't been able to find a reliable way to do this. I found some scripts but they may be outdated because they keep throwing errors. Does anyone have a solution to this? I need to send a command through Jamf Pro to all of the student Macbooks to turn off notifications before the test then send another command to re-enable them after the test. Would forcing them into Focus mode do the trick?

Here's the script I found. I modified it slightly by replacing "unload" with "bootout" using the syntax I found here:

https://joelsenders.wordpress.com/2019/03/14/dear-launchctl-were-all-using-you-wrong/

Both old and new commands are at the end of the script. I just comment out the one I don't want to test.

The errors I get are as follows:

If I use "unload" it tells me to use "bootout" instead
5: Input/output error

The script (I found this either on Jamf Nation or on GitHub after a Google search but I don't remember where):

#!/bin/sh
# Variable and function declarations
export PATH=/usr/bin:/bin:/usr/sbin:/sbin

# Get the currently logged in user
currentUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }' )

# Global check if there is a user logged in
if [ -z "$currentUser" -o "$currentUser" = "loginwindow" ]; then
echo "no user logged in, cannot proceed"
exit 1
fi

# Get the current user's UID
uid=$(id -u "$currentUser")

# Convenience function to run a command as the current user
runAsUser() {
if [ "$currentUser" != "loginwindow" ]; then
launchctl asuser "$uid" sudo -u "$currentUser" "$@"
else
echo "no user logged in"
# uncomment the exit command
# to make the function exit with an error when no user is logged in
# exit 1
fi
}

# Disable Notification Center

# Old command
# runAsUser launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist

#New command
runAsUser launchctl bootout gui/$uid /System/Library/LaunchAgents/com.apple.notificationcenterui.plist

exit 0

6 REPLIES 6

jamf-42
Valued Contributor II

can you not use a config profile with the notifications payload? 

It looks like the Notifications payload only lets you disable/enable notifications for specific apps. I want to disable all notifications. Is there another payload that'll do this without interfering with the config profile that has the restrictions?

jamf-42
Valued Contributor II

runAsUser has launchctl asuser "$uid" sudo -u "$currentUser" "$@"

so new command should be:

runAsUser bootout... etc 

removing the launchctl ? 

EDIT: use  exit $? after the command to get the correct exit code.. 

pbileci
Contributor

Bootout is part of launchctl, right? Bootout by itself doesn't work.

jamf-42
Valued Contributor II

EDIT: runASuser just reeds the bootout gui/$uid /System/Library/LaunchAgents/com.apple.notificationcenterui.plist

 

ngulick
New Contributor

Did you solve this issue? We have nearly the exact same thing, with excessive alerts appearing onscreen for student users upon login. Thank you!