1 votos

¿Cómo cambiar la configuración de las notificaciones de la aplicación de forma programada?

Hay algunas aplicaciones como WhatsApp o Telegram que no tienen una forma rápida de desactivar las notificaciones.

Me gustaría saber si es posible cambiar la configuración de las notificaciones de forma programada. En mi caso, bastaría con cambiar el interruptor de "Permitir notificaciones". Quiero establecer un acceso directo o hacer un script para activar/desactivar las notificaciones de ciertas apps.

Por si acaso, aquí hay una captura de pantalla de la configuración de la que hablo.

enter image description here

3voto

user3439894 Puntos 5883

El ejemplo AppleScript código que se muestra a continuación, se probó en script Editor en MacOS Big Sur con Lengua y región ajustes en Preferencias del sistema ajustado a Inglés (EE.UU.) - Primaria y me ha funcionado sin problemas 1 .

  • 1 Asume los ajustes necesarios y apropiados en <strong>Preferencias del sistema </strong>> <strong>Seguridad y privacidad </strong>> <strong>Privacidad </strong>se han fijado/abordado según las necesidades.

Todo lo que debería hacer es establecer el valor de targetApp al inicio de la script a la nombre de la aplicación de destino como se muestra en el Notificaciones panel en Preferencias del sistema .

Tal y como está codificado el script activa el Permitir la notificación botón de la targetApp .

El script se puede utilizar de diferentes maneras para activarlo, como un AppleScript aplicación como un Automatizador Servicio/Acción Rápida como shell script añadiendo un #!/usr/bin/osascript shebang a la parte superior de la misma, guardándola como archivo de texto simple y hacerla ejecutable con chmod o cualquier utilidad de terceros capaz de funcionar AppleScript código ., etc.

Ejemplo AppleScript código :

--  # Set the value of targetApp to the name of the
--  # target application as shown in the Notifications
--  # pane in System Preferences.

set targetApp to "Script Editor"

--  # Do not modify the code below unless necessary.

property |System Preferences| : name of ¬
    application id "com.apple.systempreferences"

--  # Check to see if System Preferences is 
--  # running and if yes, then close it.
--  # 
--  # This is done so the script will not fail 
--  # if it is running and a modal sheet is 
--  # showing, hence the use of 'killall' 
--  # as 'quit' fails when done so, if it is.
--  #
--  # This is also done to allow default behaviors
--  # to be predictable from a clean occurrence.

if running of application id "com.apple.systempreferences" then
    try
        tell application id "com.apple.systempreferences" to quit
    on error
        do shell script "killall '" & |System Preferences| & "'"
    end try
    delay 0.1
end if

--  # Make sure System Preferences is not running before
--  # opening it again. Otherwise there can be an issue
--  # when trying to reopen it while it's actually closing.

repeat while running of ¬
    application id "com.apple.systempreferences" is true
    delay 0.1
end repeat

--  # Open System Preferences to the Notifications pane.

tell application id "com.apple.systempreferences"
    run -- # Used as a workaround to an issue in Big Sur.
    delay 0.1
    reveal pane id "com.apple.preference.notifications"
end tell

--  # Use System Events to achieve the goal.

tell application id "com.apple.systemevents"
    run -- # Used as a workaround to an issue in Big Sur.
    delay 0.2
    tell window 1 of application process |System Preferences|

        --  # Wait for target pane to be available.

        my waitForUIelement(row -1 of table 1 of scroll area 1)

        --  # Ascertain the target row to select.

        set rowTargetApp to the first row of table 1 of ¬
            scroll area 1 whose value of static text 1 of ¬
            group 1 of UI element 1 is targetApp

        --  # Select the target row.

        select rowTargetApp

        --  # Wait for target checkbox to be available.

        my waitForUIelement(button 1 of group 1)

        --  # Click Allow Notifications.

        click button 1 of group 1

    end tell
end tell

delay 0.02

quit application id "com.apple.systempreferences"

--  ## Handler ##

on waitForUIelement(uiElement)
    tell application id "com.apple.systemevents"
        tell window 1 of application process ¬
            |System Preferences|
            set i to 0
            repeat until exists uiElement
                delay 0.1
                set i to i + 1
                if i ≥ 30 then return
            end repeat
        end tell
    end tell
end waitForUIelement

Notas:

Tal y como está codificado el script simplemente cambia el Permitir la notificación botón de la targetApp Sin embargo, el código puede modificarse fácilmente para comprobar el estado del objetivo botón y actuar en consecuencia. Por ejemplo, si uno quiere asegurarse de que está desactivado.

Cambios:

click button 1 of group 1

Para:

if value of button 1 of group 1 is "on" then ¬
    click button 1 of group 1

Para uso en MacOS Catalina :

Cambios:

    --  # Ascertain the target row to select.

set rowTargetApp to the first row of table 1 of ¬
    scroll area 1 whose value of static text 1 of ¬
    group 1 of UI element 1 is targetApp

Para:

    --  # Ascertain the target row to select.

set rowTargetApp to first item of (rows of table 1 of ¬
    scroll area 1 whose value of static text 1 of ¬
    group 1 of UI element 1 is targetApp)

Nota: El <em>ejemplo </em><strong>AppleScript </strong><em>código </em>es sólo eso y sin ningún tipo de inclusión <em>tratamiento de errores </em>no contiene ningún otro <em>tratamiento de errores </em>según corresponda. Corresponde al usuario añadir cualquier <em>tratamiento de errores </em>como sea apropiado, necesario o deseado. Eche un vistazo a la <a href="https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_control_statements.html#//apple_ref/doc/uid/TP40000983-CH6g-129232" rel="nofollow noreferrer"><strong>intente </strong></a><em>declaración </em>y <a href="https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_control_statements.html#//apple_ref/doc/uid/TP40000983-CH6g-129657" rel="nofollow noreferrer"><strong>error </strong></a><em>declaración </em>en el <a href="https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html" rel="nofollow noreferrer"><strong>Guía del lenguaje AppleScript </strong></a>. Véase también, <a href="https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_error_xmpls.html#//apple_ref/doc/uid/TP40000983-CH221-SW1" rel="nofollow noreferrer"><strong>Trabajar con errores </strong></a>. Además, el uso del <a href="https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW10" rel="nofollow noreferrer"><strong>retraso </strong></a><em>comando </em>puede ser necesario entre eventos cuando sea apropiado, por ejemplo <code>delay 0.5</code> con el <em>valor </em>de la <em>retraso </em>ajustado apropiadamente.

AppleAyuda.com

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.

Powered by:

X