I’m trying to select multiple folders in the front most window and would like to take screenshot of the same. But my script open multiple windows and showing the selected folder. Is there any way to multi select the folders in one window.
tell application "Finder"
set thelist to {"Published", "Creative", "ArtPro", "Page_Layouts", "Readers Single", "Readers Spread", "Xproof", "PDF", "CAD"}
set folderpath to (choose folder)
set thefolders to every folder of entire contents of folderpath
repeat with objItem in thefolders
set ParentFolder to container of objItem -- sets the parent folder
set Foldername to name of objItem as text -- sets the folder name as text
if name of objItem is in thelist then
select objItem
end if
end repeat
end tell
set saveToPath to ((POSIX path of (path to desktop)) & fileNames & "-" & ".pdf") as string
do shell script "screencapture -w -o -tpdf -x " & quoted form of saveToPath
selection property and select command both works with lists. So setting a list of file specifiers will work too:
tell application "Finder"
set thelist to {"Published", "Creative", "ArtPro", "Page_Layouts", "Readers Single", "Readers Spread", "Xproof", "PDF", "CAD"}
set foldersToSelect to {}
set folderpath to (choose folder)
set thefolders to every folder of entire contents of folderpath
repeat with objItem in thefolders
set ParentFolder to container of objItem -- sets the parent folder
set Foldername to name of objItem as text -- sets the folder name as text
if name of objItem is in thelist then
set end of foldersToSelect to objItem
end if
end repeat
select foldersToSelect
end tell
set saveToPath to ((POSIX path of (path to desktop)) & fileNames & "-" & ".pdf") as string
do shell script "screencapture -w -o -tpdf -x " & quoted form of saveToPath
This works much better. Still needs minor improvement. Is there any way to display a list of ALL selected folders in one window? At the moment each parent folder along with its selected child folders are opened in separate window.
And btw, you can completely expand a folder in list view by using McUsrII’s Tree app. I think it still works sometimes, but it is very complicated. You can try searching for that.
Edited: yes it worked to completely expand on my first try. It didn’t collapse the list view though.
I did a quick review of completely expanding folders and basically, what you need to do is Command + Option + right arrow. I forgot what were the complications, but maybe McUsr might reply.
Edited: I think it had something to do with timing.
Edited: oh no. Option + right arrow seems to do it. I’ve forgotten.
Edited: forgot that you need to select all first. Also, if the folder is really big (like your home folder) then you need to speed that up. That’s what McUsr was doing.
Here’s an example which completely expands and set label index of a random item:
property label_index : 4 -- blue
set desktop_ref to path to desktop
tell application "Finder"
activate
open desktop_ref
end tell
tell application "System Events"
keystroke "a" using command down
key code 124 using option down
end tell
delay 1
tell application "System Events" to keystroke "a" using {command down, option down}
delay 1
tell application "Finder"
set entire_contents to every item of entire contents of desktop_ref
set some_item to some item of entire_contents
set label index of some_item to label_index
set window_id to id of front window
end tell
delay 1
set posix_file_spec to quoted form of ((POSIX path of desktop_ref) & "Snapshot.png")
do shell script "screencapture -l " & window_id & space & posix_file_spec
-- NOTE: that if the window has too many items, then all items will not show.
-- Still working on that and have a couple of options in mind.
I might just expand those folders that have labeled items.
Edited: made corrections with wrong variable name.
Edited: oops, forgot to use ‘every item of entire contents’. Last update.
Edited: darn, may have needed a delay after setting the label index.