Usando Automator para configurar las ventanas del Finder

0

Utilizo las ventanas del Finder para mostrar imágenes de los empleados de mi empresa en una pantalla de TV. Una ventana del buscador para cada departamento. Las diferentes ventanas del Finder se ajustan para adaptarse a dos pantallas de TV 4K. ¿Hay alguna forma de utilizar Automator o AppleScript para guardar y recuperar esta configuración exacta cuando sea necesario?

    
pregunta oystein 21.08.2016 - 11:45

1 respuesta

1

El script de muestra a continuación está codificado con los siguientes supuestos: desea que las ventanas del Finder objetivo sean lo más sencillas posible, es decir, que no se muestren la Barra de ruta, el Panel de vista previa, la Barra de herramientas, la Barra lateral o la Barra de estado solo una ventana plana en la vista Icono con la Barra de título que muestra el nombre del Departamento con los iconos de imagen que muestran una vista previa de la imagen y la configuran en un tamaño determinado con la etiqueta que se muestra debajo de la imagen. Otras configuraciones requerirán lógica adicional y / o codificación. Nota: vea los comentarios en el código si desea establecer una imagen o un color para un fondo común de todas las ventanas del Buscador de carpetas de destino que deseen mostrarse y organizarse.

Para el entorno de prueba, utilicé mi MacBook Pro y Thunderbolt Display configurados con el MacBook Pro como pantalla principal con la barra de menús y el Thunderbolt Display a su derecha. El script abre las cuatro ventanas de búsqueda de destino de ejemplo, establece los requisitos de visualización y los organiza en la pantalla Thunderbolt como se muestra en la imagen a continuación.

Parausarestescript,deberárecopilarinformacióndesuescenariototalmenteconfiguradoyrealizarloscambiosnecesariosencódigoy,parahacerlo,hagalosiguiente:

  • Primero,abralascarpetasdedestinoyorganícelasenla(s)pantalla(s)parasatisfacersusnecesidades/deseos.

  • Nota:parafacilitarlo,altenermenosinformaciónparaanalizarenelsiguientepaso,cierretodaslasdemásventanasdelFinder.

  • AbraelEditordesecuenciasdecomandosyenunanuevaventanaquenotengacódigo,useelsiguientecomandoparaobtenerlaspropiedadesdelasventanasdelBuscadordeobjetivosabiertasyorganizadas:

    tellapplication"Finder" to get properties of windows

  • En el panel Resultados, verá mucha información que puede parecer imposible de discernir, sin embargo, no será tan difícil. Es posible que desee copiar y pegar esta información en TextEdit para hacer un poco de análisis y tener la información lista para copiar y pegar en el script , según sea necesario.

    A partir de la información recopilada, deseará principalmente dos piezas de información para cada ventana del Finder de destino, su name y bounds . Puede ver en el código cómo se ve la información de bounds y cómo se aplica.

  • Obtendrás las propiedades de vista adicionales necesarias de Mostrar opciones de vista al seleccionar una ventana de destino y luego hacer clic en 'Finder > Ver > Muestre las opciones de visualización ⌘J 'o simplemente presione J después de seleccionar una ventana de destino. Vea los comentarios en el código sobre la información de "Mostrar opciones de visualización".

  • Copie y pegue el código a continuación desde el navegador a una nueva ventana en el Editor de secuencias de comandos y luego haga clic en el botón Compilar para asegurarse de que no haya errores iniciales en el código actual . Los comentarios y el código ahora serán mucho más fáciles de discernir, ya que el Editor de secuencias de comandos aplicará el resaltado sintáctico adecuado al código , algo que el navegador simplemente no hace correctamente.

    Debería poder seguir los comentarios a lo largo del script para modificarlo para su caso de uso. Si tiene alguna pregunta, solo pregunte.

#
##        READ COMMENTS FOR AN UNDERSTANDING OF WHAT THE CODE IS DOING
##        AND WHAT INFORMATION YOU'LL NEED TO PROVIDE AND OR MODIFY.
#
#
#    The 'gTargetPath' variable is a global (to the script only) variable being set for
#    the path to the target folders Finder is to open and arrange, that which contain
#    the Company's employee pictures which are arranged in separate folders by
#    their respective Departments.
#
#    It's assuming a logical hierarchical folder structure where the starting point
#    is in the User's Picture folder (or other location) and progresses e.g., 
#    Company > Departments > Department Name. Obviously you'll need to
#    modify it to suite your needs. Note however, this script is coded with the
#    assumption that all target folders to be opened are all in a given parent
#    folder so as to only have to set the path to the containing parent folder.
#
#    Thus only having to provide the 'name' of each target folder and its
#    'bounds' info, for them to be programmatically opened and arranged
#    on the attached Display(s) per the other relevant setting in the script.
#
#    Note: If the target folders to be opened are not in a centralized parent
#    folder then create Aliases for the folders and place them in a centralized
#    parent folder so as to maintain a single path to use in this script.
#

global gTargetPath

set gTargetPath to (path to pictures folder as text) & "Company:Departments:"

#
#    This first 'tell application "Finder"' statement block is where
#    you'll set the 'name' of the target folders with its 'bounds' info.
#
#    The example settings should serve as a guide. Each Department
#    code block consists of two 'set' statements and the calling of the
#    'arrangeWindow(folder_name, window_bounds)' subroutine, which
#    itself does not need to be modified.
#
#    Just provide the info, as the example info for each folder shows.
#

tell application "Finder"
    activate

    ###    Accounting    ###

    set folder_name to "Accounting"
    set window_bounds to {1495, 36, 2252, 706}

    my arrangeWindow(folder_name, window_bounds)


    ###    Marketing    ###

    set folder_name to "Marketing"
    set window_bounds to {2321, 36, 3075, 706}

    my arrangeWindow(folder_name, window_bounds)


    ###    Production    ###

    set folder_name to "Production"
    set window_bounds to {3156, 36, 3912, 706}

    my arrangeWindow(folder_name, window_bounds)


    ###    Sales    ###

    set folder_name to "Sales"
    set window_bounds to {2320, 757, 3075, 1426}

    my arrangeWindow(folder_name, window_bounds)

end tell

#
##
###    Begin Subroutines        ###
##
#
#    ONLY THIS FIRST SUBROUTINE SHOULD NEED TO BE MODIFIED.
#
#    Read comments for an understanding of what the code is doing
#    and what information you'll need to provide and or modify.
#
#    The 'setFinderViewShowViewOptions(folder_name)' subroutine handles the setting
#    available when using 'Finder > View > Show View Options  ⌘J' and the values of
#    some may/will need to be modified to suite your use case.
#
#    The current setting are what were used in the test example and I'd imagine you'd
#    only have to change 'set icon size to' and 'set text size to', to the value you need.
#
#    The other setting are conducive to what I believe one would want and shouldn't 
#    need adjusting. That is sans the settings if using a picture or other then default
#    color for the background in Icon view. See additional comments around each.
#

on setFinderViewShowViewOptions(folder_name)

    #    Finder > View > Show View Options  ⌘J

    tell application "Finder"
        activate window named folder_name
        tell icon view options of window folder_name
            set arrangement to arranged by name # See Finder's AppleScript Dictionary for other values.
            set icon size to 256
            set shows item info to false
            set shows icon preview to true
            set text size to 12 # Valid values: 10~16
            set label position to bottom # Valid values: [right|bottom]

            #
            ##
            ###    THE NEXT TWO PROPRIETIES CAN ONLY BE USED ONE AT A TIME!
            ##
            #
            #    For 'set background picture to (file)', remove '(*' and '*)' to
            #    activate the 'try' code block while modifying the example
            #    path to reflect the correct POSIX path to the target image file
            #    to be used for the background.
            #
            #    Note: If the image dimensions are larger then the window,
            #    it displays only the portion starting in the upper right corner
            #    of the image and starting in the upper right corner of the
            #    window. Right sizing the image to fit the size of the window
            #    ahead of time may be necessary.
            #

            (*
                try
                    set background picture to POSIX file "/Users/me/Pictures/IMG_0866.JPG"
                    tell application "Finder"
                        close Finder window named folder_name
                        open gTargetPath & folder_name
                    end tell
                end try
            *)

            #
            #    'set background color to {RGB color * 257 for each value of RGB.}'
            #
            #    For example, a color of 85% grayscale would be '217, 217, 217' in RGB color.
            #    Multiply each RGB value by 257, e.g, 217*257=55769 so the 'set ...' command
            #    below would set the background color to 85% grayscale.
            #
            #    Remove the '-- ' from in front of '-- set ...' to activate the code.
            #

            -- set background color to {55769, 55769, 55769}

        end tell
    end tell

end setFinderViewShowViewOptions

#
##
###    THE SUBROUTINES BELOW SHOULD NOT NEED TO BE MODIFIED.        ###
##
#
#    The 'setFinderView(folder_name)' subroutine programmatically handles setting
#    the 'Finder > View' menu setting for hiding the Toolbar and Status Bar.
#
#    All other [Hide/Show ...] 'View' menu commands require GUI Scripting and
#    are handled by the 'setFinderViewGUI()' subroutine following below this one.
#

on setFinderView(folder_name)

    #     Finder > View > [as Icons (icon) | as List (list) | as Columns  (column) | as Cover Flow (flow)]
    #     Finder > View > [Hide/Show Toolbar]
    #     Finder > View > [Hide/Show Status Bar]

    tell application "Finder"
        activate window named folder_name
        try
            set the current view of window folder_name to icon view
            set toolbar visible of window folder_name to false
            set statusbar visible of window folder_name to false
        end try
    end tell
end setFinderView

#
##
###      THE USE OF 'setFinderViewGUI()' REQUIRES PERMISSION FOR ASSISTIVE ACCESS.        ###
##
#
#    This subroutine handles clicking, as applicable, "Hide Tab Bar", "Hide Path Bar" and "Hide Preview"
#    on the View menu in Finder. These are not programmatically scriptable in the same manner as
#    selecting the current view to e.g. 'as Icons'. Or 'Hide/Show Toolbar' and 'Hide/Show Status Bar'
#    and as such requires GUI Scripting and thus requires permission to do so.
#
#    See https://support.apple.com/HT202802 for additional information and note while the article
#    is named "OS X: Using AppleScript with Accessibility and Security features in Mavericks",
#    nonetheless it's applicable to later versions of OS X too.
#

on setFinderViewGUI(folder_name)
    tell application "Finder"
        activate window named folder_name
        tell application "System Events"
            set menuViewItems to get name of menu items of menu 1 of menu bar item "View" of menu bar 1 of process "Finder"
            try
                considering case
                    if menuViewItems contains {"Hide Tab Bar"} then
                        click menu item "Hide Tab Bar" of menu 1 of menu bar item "View" of menu bar 1 of process "Finder"
                    end if
                    if menuViewItems contains {"Hide Path Bar"} then
                        click menu item "Hide Path Bar" of menu 1 of menu bar item "View" of menu bar 1 of process "Finder"
                    end if
                    if menuViewItems contains {"Hide Preview"} then
                        click menu item "Hide Preview" of menu 1 of menu bar item "View" of menu bar 1 of process "Finder"
                    end if
                end considering
            end try
        end tell
    end tell
end setFinderViewGUI

#
#    The 'arrangeWindow(folder_name, window_bounds)' subroutine handles
#    the processing of the other subroutines so all settings are applied to each
#    Finder window for which a folder name and the window 'bounds' have been
#    supplied in the beginning of this script in the first 'tell application "Finder"'
#    statement block. This subroutine should not have to be modified.
#
#    Thus minimizing the amount of script modifications to achive what I think
#    would be for a reasonable appearance in the overall window that is
#    displaying the photos. Which is to hide all non-essential window controls
#    to provide a clean and uncluttered look giving the pictures better focus.
#

on arrangeWindow(folder_name, window_bounds)
    tell application "Finder"
        open gTargetPath & folder_name
        my setFinderView(folder_name)
        my setFinderViewGUI(folder_name)
        my setFinderViewShowViewOptions(folder_name)
        set bounds of window named folder_name to window_bounds
    end tell
end arrangeWindow

#
##
###    End Subroutines      ###
##
#
    
respondido por el user3439894 23.08.2016 - 21:01

Lea otras preguntas en las etiquetas