Choose file with multiple selections

OK, I need a scriptlet that does the following:

  1. In Interface Builder, I make an empty text field with the drop enabled

  2. When something is dropped to it, save the file path as a POSIX path to a different variable for every file dropped

  3. Display the file paths in the text field

I got the first part, but I’m having trouble going anywhere after that.

I don’t think you can set each of the file paths to a different variable unless you know exactly how many files are going to be dropped and the number never changes.

Why wouldn’t you add all the file paths to a list and then when you want to do whatever it is you want to do you cycle through the list.

repeat with aFile in filePaths
–do whatever to aFile
end repeat

If you add a text view to a window named “main” and add a drop handler to it this will work. I’m sure there is a better way but this will get you going.

on awake from nib theObject
	tell theObject to register drag types {"file names"}
end awake from nib

on drop theObject drag info dragInfo
	set theFiles to {}
	set preferred type of pasteboard of dragInfo to "file names"
	set theFiles to contents of pasteboard of dragInfo
	repeat with aFile in theFiles
		set newContent to (aFile as string) & return
		set allContent to contents of text view "textView" of scroll view "scrollView" of window "main" & newContent
		set contents of text view "textView" of scroll view "scrollView" of window "main" to allContent
	end repeat
	log theFiles
	return true
end drop

Dropping files onto a text field works out of the box for me. Could you just leave the drop support alone and use a conclude drop or clicked (on a button) handler instead?

TYVM, I’ll check this out :slight_smile: