Select multiple folders in different directories

Hi all,

I would like to get the contents of multiple folders (let’s say 3 or 4) which are located in different directories.
Is that possible? Any idea how to select multiple folders in different directories?

I was planning to have a repeat loop of choosing one folder at time (and save each time its location), until the user “Cancel”.
The “Cancel” will trigger the “enough folders selected”, and then start processing the files in each folder which was selected before canceling…

Any better idea?

Thanks

L.

UI-wise for the user, I’d suggest having them make a new finder tab for each parent folder they need to select subfolders in, and select them. That way they can get all of them selected at once, wherever they are, without repeated prompts.

The downside to that is that Apple never updated the Finder dictionary to know about Finder tabs, so going through the tabs to find the selected folders is a bit of a PITA compared to what it should be, because it has to be done with UI scripting.

But all the UI script has to do is iterate through selecting each tab - once a tab is frontmost, normal Applescript using the Finder’s dictionary can get the selected subfolders and add them to the list.

Thanks t.spoon!

I actually made this script, which seems to work.

set theFolders to {}
repeat
	try
		set theFolders to theFolders & (choose folder with multiple selections allowed)
		get theFolders
	on error
		display notification "Exiting"
		exit repeat
	end try
	display notification "Following"
end repeat
get theFolders

But then I made this and somehow it also works:

set theFolders to {}
repeat
	try
		set end of theFolders to (choose folder with multiple selections allowed)
		get theFolders
	on error
		display notification "Exiting"
		exit repeat
	end try
	display notification "Following"
end repeat
get theFolders

but the final lists I get are different.
With the script #1 it is a “pure” list of items.And each item contains the path to the folder.
With the script #2 to is also a list of items, but each item contains a subitem …
I don’t understand the difference.

“Choose folder” returns a list.

The “&” operator concatenates the items of lists.

“Set end of” will place the new item at the end of the list.

So when you use the “&” operator on two lists, the result is a new list containing all the items of the two lists. When you use “set end of,” then it makes the last item in the list you’re changing the other list.

set list1 to {"Peter", "Paul", "Mary"}
set list2 to {"John", "George", "Paul"}
set emptyList to {}

set combinedListWithAnd to emptyList & list1 & list2
set combinedListWithTheEnd to emptyList
set the end of combinedListWithTheEnd to list1
set the end of combinedListWithTheEnd to list2

result
combinedListWithAnd:

combinedListWithTheEnd:

Thanks a lot t.spoon ! I got it now.

And I can see the power of this !

L.