0

I use Finder windows to display pictures of the my company's employees on a TV screen. A Finder window for every department. The different Finder windows are adjusted to fit in to two 4K TV screens. Is there a way to use Automator or AppleScript to save and recall this exact configuration when needed?

  • The short answer is yes, using AppleScript, however the longer answer is a bit complex for a comment. There may be a app out there that can help automate the process, so you might want to do a little googling. I don't have time today to post an answer of how I do something similar with arranging Finder windows, based on which screen has focus, however after all windows were arranged I used tell application "Finder" to get properties of windows and then parsing and using the results... I used set ... etc. I know that doesn't help much, but it's a starting point to google with. – user3439894 Aug 21 '16 at 10:53
  • Not sure if you've seen my answer yet, however I've modified the code and comments. So if you have see it and have started to implement it, then you should use the code changes I've made. – user3439894 Aug 24 '16 at 17:06
  • @user3439894. That's brilliant. Thank you very much. I will look in to your work and try to adapt it to my needs. – oystein Aug 25 '16 at 3:55
1

The sample script below is coded with the following assumptions, you want the target Finder windows to be as plain as possible, i.e. no Path Bar, Preview pane, Toolbar, Sidebar or Status Bar showing, just a plain window in Icon view with the Title Bar showing the Department name with the picture icons showing a preview of the image and set to a given size with the label shown below the image. Other configurations will require additional logic and or coding. Note: See comments in the code if wanting to set a picture or color for a common background of all target folder Finder windows wanting to be displayed and arranged.

For the test environment I used my MacBook Pro and Thunderbolt Display configured with the MacBook Pro as the main screen with Menu bar and the Thunderbolt Display to its right. The script opens the four example target Finder windows, sets the view requirements and arranges them on the Thunderbolt Display as shown in the image below.


Thunderbolt Display Image


To use this script you'll need to gather information from your fully configured scenario and make the necessary code changes and to do that, do the following:

  • First, open the target folders and arrange them on the screen(s) to suite your needs/wants.

  • Note: To make it easier, by having less information to parse in the next step, close all other Finder windows.

  • Open Script Editor and in a new window that has no code in it, use the following command to get the proprieties of the arranged opened target Finder windows:

    tell application "Finder" to get properties of windows

  • In the Results pane, you'll see a lot of information that may look impossible to discern, however it won't be that difficult. You might want to copy and paste this info into TextEdit to do a bit of parsing and have the info ready to copy and paste into the script, as will be needed.

    From the information gathered you'll primarily want two pieces of info for each target Finder window, its name and bounds. You can see in the code what the bounds info looks like and how it's applied.

  • You'll get the additional view properties needed from Show View Options by selecting a target window and then click 'Finder > View > Show View Options ⌘J' or just press J after selecting a target window. See comments in the code about the 'Show View Options' information.

  • Copy and paste the code below from the Browser to a new window in Script Editor and then click the Compile button to ensure there are no initial errors in the current code. The comments and code will now be much easier to discern as the Script Editor will apply proper syntactical highlighting to the code, something the Browser just doesn't properly do.

    You should be able to follow the comments throughout the script in order to modify it for your use case. If you have any questions, just ask.


#
##        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      ###
##
#

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .