0 votos

Cambiar la escala de la pantalla del MacBook mediante AppleScript

Estoy intentando cambiar la configuración de escala de mi MacBook Pro 14" mediante AppleScript.
El ajuste debe alternar dos ajustes de resolución.
He encontrado el siguiente script aquí: https://stackoverflow.com/a/62664159/15705553

on run {input, parameters}

    tell application "System Preferences"
        reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
    end tell

    set lowResolutionSettingIndex to 4
    set highResolutionSettingIndex to 5

    tell application "System Events" to tell process "System Preferences" to tell window "Built-in Retina Display"
        click radio button "Display" of tab group 1
        click radio button "Scaled" of tab group 1
        tell radio group 1 of group 1 of tab group 1
            set isHighResolutionSet to get value of radio button highResolutionSettingIndex
        end tell
        if isHighResolutionSet then
            -- Toggle native resolution
            click radio button lowResolutionSettingIndex of radio group 1 of group 1 of tab group 1
        else
            -- Toggle Default setting - "Retina optimized"
            click radio button highResolutionSettingIndex of radio group 1 of group 1 of tab group 1
        end if
    end tell

    quit application "System Preferences"

    return input
end run

He cambiado "Pantalla Retina incorporada" por "Pantalla Retina líquida XDR incorporada" como se muestra en mis Preferencias del Sistema, pero se producen dos errores:

  • Si ejecuto este script a través de Automator, obtengo el siguiente error:

    Syntax Error: System Events got an error: Can’t get window "Built-in Liquid Retina XDR Display" of process "System Preferences".

  • Si lo ejecuto a través de shortcuts.app, obtengo el siguiente error, a pesar de que he concedido acceso a las funciones de accesibilidad para Shortcuts en las Preferencias del Sistema

    System Events got an error: Shortcuts is not allowed assistive access.

1voto

dAdOuCx Puntos 6

Por cierto, he tenido éxito cambiando la escala de pantalla de un Mac con este script:

-- This script toggles a display's resolution between "Default for Display" and "Scaled" (at the largest scale factor.)

on run

    -- Make sure System Preferences is open, and view the "Displays" preferences pane
    tell application "System Preferences"
        activate
        reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
        repeat until window "Displays" exists
            delay 0.1
        end repeat
    end tell

    tell application "System Events" to tell process "System Preferences"

        -- Bring up the "Display Settings" sheet, where the UI to change scaling is
        click button "Display Settings…" of window 1

        delay 0.2

        -- I'm only changing the scale of my 2nd monitor, which for me is the second display listed in the left-hand scroll area, so I need to click that 2nd row first.
        -- If you want to change the scale of your main display instead, just delete this tell block.
        tell outline 1 of scroll area 1 of sheet 1 of window 1
            set selected of row 2 to true
        end tell

        tell sheet 1 of window 1
            -- Is that display currently scaled?  If so, go back to the default resolution.  If not, then scale it.
            set theScaledRadioButton to radio button "Scaled" of radio group 1
            set isCurrentlyScaled to value of theScaledRadioButton as boolean
            if isCurrentlyScaled then
                click radio button "Default for Display" of radio group 1
            else
                click radio button "Scaled" of radio group 1
                -- If you want a different amount of scaling, change this button to "Resolution5" or "Resolution4", etc. down to "Resolution1"
                click button "Resolution5" of UI element 6
            end if

            -- Dismiss the "Display Settings" sheet, we're done using it.
            click button "Done"
        end tell

    end tell

    delay 0.1
    tell application "System Preferences"
        close window 1
    end tell

    -- Commented out, since I prefer to leave System Preferences open in the background so this script runs faster on the next run.
    --quit application "System Preferences"

end run

Ten en cuenta que también tendrás que ir a Preferencias del Sistema > Seguridad > Accesibilidad y marcar la casilla para dar permiso a Automator o a cualquier otra aplicación para controlar tu ordenador.

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