I have a droplet that takes a (only one) folder dropped on it, which folder may contain subfolders.
I wanted the script to also have a run handler, with a choose folder, so I coded
on run tell me to open (choose folder) --> returns an alias which is passed to open handler end run on open chosenFolder --> dropped folder is passed as a list of 1 item tell application "Finder" set theSources to (items of folder chosenFolder) -->"Can't make some data into expected type" when as droplet. end tell end open
When double-clicked, the script runs fine - the Open handler gets passed an alias, which works fine.
When used as a droplet, the set theSources line errors trying to convert a list into an alias.
I understand what’s going on here, as I have in the past had to use “item 1 of” to get rid of the list. But in this case, using “item 1 of” does not get all the items when the script is run by using the Run Handler.
I worked around it by converting the alias returned by Choose Folder to a list using this code:
on run set chooseFolderAlias to (choose folder) set chosenFolderList to (chooseFolderAlias as list) tell me to open chosenFolderList end run on open chosenFolder tell application "Finder" set theSources to items of item 1 of chosenFolder end tell end open
Is this the recommended way to make sure a list gets passed to the Open handler? Or is there an easier way?