Okay, this is driving me nuts, since it seems so straightforward…
I’ve searched the archives and tried at least a dozen variations on the theme, but I keep getting an “Uknown Object” error no matter what I try.
I have a droplet that needs to take folder, files, or a mix of folders and files, and perform tasks all the files, including files inside subfolders.
The first trick was easy, getting the initial list from the “on open” handler and differentiating between folders and files. As I understand it, files/folders dragged onto a droplet become a list of aliases sent to the variable name of the “on open” handler.
Now what I want to do loop through each of those aliases and whenever it hits a folder, to get an alias list of all the items within that folder, then add them to the existing list created by the “on open” handler.
I thought this short, sweet code block would grab me that subfolder list…
tell application "Finder"
set subfolder_list to (current_path's entire contents as list)
set end of actionItems to subfolder_list
end tell
Where “actionItems” is the “on open” handler’s name/variable.
…but as I said, I keep getting an “Unknown Object” error when it hits the first “set” command. Near as I can tell it never gets to the second “set.”
I’ve tried every variation of “entire contents” I could find via search. They all give the same error. I can’t seem to find “entire contents” in the Finder’s Library for a syntax description either.
set current_path to path to desktop
set actionItems to {}
tell application "Finder"
set subfolder_list to (current_path's entire contents)
set end of actionItems to subfolder_list
end tell
My results (as written) give me a subfolder_list with every folder and file (including subfolders and their files) of my desktop. The actionItems then contains the single subfolder_list.
Assuming that current_path is an alias to a folder and you want aliases for the folder’s entire contents:
tell application "Finder"
set contents_list to current_path's entire contents as alias list
end tell
If you only need aliases for the files in that hierarchy:
tell application "Finder"
set contents_list to files of current_path's entire contents as alias list
end tell
There’s a long-standing Finder bug whereby as alias list errors if there’s only one item to convert, so:
tell application "Finder"
try
set contents_list to files of current_path's entire contents as alias list
on error
set contents_list to {first file of current_path's entire contents as alias}
end
end tell
If you want to add those aliases (rather than the list that contains them) to the list you already have, it’s easiest to concatenate the lists together:
tell application "Finder"
try
set contents_list to files of current_path's entire contents as alias list
on error
set contents_list to {first file of current_path's entire contents as alias}
end
end tell
set actionItems to actionItems & contents_list
No that’s not what I want…I want to append one list onto the end of an existing list. The references I found said the command I used should do that. If that’s not the case, how do you simply “tack on” one list to another and simply yield one larger list?
[EDIT: Nevermind, just saw the next post by Nigel and I think it answers my question. I’ll let y’all know.]
I feel kinda silly, since I was going to do it this way (this self-modification construct has been around since at least line-BASIC) but the “stick it at the end” syntax I found seemed so much more “Applescripty.”
I used this last chunk you provided, swapped my variable names, and voilà it all worked like a charm.
Thanks, I think this is at least the second time you’ve solved a head-banger for me Nigel.