Lo script di esempio sotto è codificato con le seguenti ipotesi, vuoi che le finestre del Finder di destinazione siano il più semplici possibile, ovvero nessuna barra del percorso, riquadro di anteprima, barra degli strumenti, barra laterale o barra di stato che mostra, solo una semplice finestra in vista Icone con la barra del titolo che mostra il nome del reparto con le icone delle immagini che mostrano un'anteprima dell'immagine e impostate su una determinata dimensione con l'etichetta mostrata sotto l'immagine. Altre configurazioni richiedono ulteriore logica e / o codifica. Nota: vedere i commenti nel codice se si desidera impostare un'immagine o un colore per uno sfondo comune di tutte le finestre del Finder che desiderano essere visualizzate e organizzate.
Per l'ambiente di test ho utilizzato MacBook Pro e Thunderbolt Display configurati con MacBook Pro come schermata principale con la barra dei menu e il display Thunderbolt alla sua destra. Lo script apre le quattro finestre di Finder target di esempio, imposta i requisiti di visualizzazione e li dispone sul Display Thunderbolt come mostrato nell'immagine seguente.
Perutilizzarequestoscriptdovrairaccogliereinformazionidalloscenariocompletamenteconfiguratoeapportarelenecessariemodifichealcodiceefareciò,faiquantosegue:
Perprimacosa,aprilecartelledidestinazioneedisponilisulloschermo(s)persoddisfareletueesigenze/desideri.
Nota:persemplificare,avendomenoinformazionidaanalizzarenelpassaggiosuccessivo,chiudituttelealtrefinestredelFinder.
ApriScriptEditoreinunanuovafinestrachenoncontienealcuncodice,usailseguentecomandoperottenereleproprietàdellefinestredelFinderdidestinazioneaperteeorganizzate:
tellapplication"Finder" to get properties of windows
-
Nel riquadro Risultati, vedrai molte informazioni che potrebbero sembrare impossibili da comprendere, tuttavia non sarà così difficile. Potresti voler copiare e incollare queste informazioni in TextEdit per fare un po 'di analisi e avere le informazioni pronte per copiare e incollare nello script , come sarà necessario.
Dalle informazioni raccolte vorrai principalmente due informazioni per ogni finestra del Finder target, il suo name
e bounds
. Puoi vedere nel codice quali sono le informazioni bounds
e come sono applicate.
-
Otterrai le proprietà di visualizzazione aggiuntive necessarie da Mostra opzioni di visualizzazione selezionando una finestra di destinazione, quindi fai clic su "Finder > Visualizza > Mostra le opzioni di visualizzazione ⌘J 'o premi ⌘ J dopo aver selezionato una finestra di destinazione. Vedi i commenti nel codice sulle informazioni "Mostra le opzioni di visualizzazione".
-
Copia e incolla il codice sotto dal Browser in una nuova finestra in Script Editor e poi fai clic sul pulsante Compila per assicurarti che non ci siano errori iniziali nel codice corrente . I commenti e il codice ora saranno molto più facili da distinguere poiché lo Script Editor applicherà l'evidenziazione sintattica corretta al codice , qualcosa che il Browser non fa proprio correttamente.
Dovresti essere in grado di seguire i commenti in tutto lo script per modificarlo per il tuo caso d'uso. Se hai domande, chiedi pure.
#
## 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 ###
##
#