¿Cómo comprobar si las notificaciones están activadas o no para mi aplicación desde el terminal / línea de comandos en MacOS Big Sur?
Además, quiero activar o desactivar por la fuerza las notificaciones utilizando privilegios administrativos/Root.
¿Cómo comprobar si las notificaciones están activadas o no para mi aplicación desde el terminal / línea de comandos en MacOS Big Sur?
Además, quiero activar o desactivar por la fuerza las notificaciones utilizando privilegios administrativos/Root.
Por fin, después de pasarme todo el día leyendo cientos de artículos y post, he encontrado la respuesta. Basta con sustituir <your app bundle id>
con el ID del paquete para el que desea realizar la comprobación.
#!/bin/bash
# check whether notifiactions are enabled for logged in user or not
# if not enabled, enable it for your app
# Get the current logged in user
user=$(echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }')
#Location of the notification center preferences plist for the current user
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")
#Flag to indicate if the notification center should be restarted
restart=0
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}");
if [[ $flags_value == 276* ]]; then
/usr/libexec/PlistBuddy -c "Set :apps:${index}:flags 41951246" "${notification_plist}"
restart=1
fi
fi
done
if [[ ${restart} = 1 ]]; then
# Restart notification center to make changes take effect.
killall sighup usernoted
sleep 1
# wait for notification center to start again
while ! pgrep -x "usernoted" >/dev/null; do sleep 1; done
fi
El código anterior me ha funcionado. Otros pueden necesitar ajustar valor_bandera según sus necesidades.
AppleAyuda es una comunidad de usuarios de los productos de Apple en la que puedes resolver tus problemas y dudas.
Puedes consultar las preguntas de otros usuarios, hacer tus propias preguntas o resolver las de los demás.