Path of Drag and Drop item

hi
im creating a program that has one part in it where it needs to get the path to the application being dropped via drop box. However, i have never had deal with drag and drop before. I have taken a look at “Drag and Drop” in the Developers/…/AS Studio folder but that only confused me more.
So my question to you is how do I get the path to the app that has been dropped in the drop box?

~Balthamos

Greetings. It’s best to create a droplet application from the beginning because it will have built-in support for the dropping of items. Use the code below in the ‘on drop’ handler to get the list of dropped items. Even if you only drop one item, it still returns it as a list of one item. To use all of the items of the drop, use the repeat loop to cycle through them. To just evaluate the one item dropped, use the “…item 1…” code. Note that if you drop more than one item with the ‘item 1’ code that it will process whichever one was highlighted first. Also, remember to connect the ‘awake from nib’ event of your drop object to the code below in the awake from nib handler, or the file name types will not be activated for that object.

on drop theObject drag info dragInfo
	set dataTypes to types of pasteboard of dragInfo
	if "file names" is in dataTypes then
		set preferred type of pasteboard of dragInfo to "file names"
		set thePaths to contents of pasteboard of dragInfo
		set preferred type of pasteboard of dragInfo to ""

		(* Loop through all items dropped *)
		repeat with thePath in thePaths
			set theFile to (POSIX file thePath as string) as file specification
			-- Do something here --
		end repeat

		(* Work with only the first item dropped *)
		set thePath to item 1 of thePaths
		set theFile to (POSIX file thePath as string) as file specification
		-- Do something here --

	end if
end drop

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

“thePaths” = the raw list of paths to the items dropped on the object
“thePath” = the current raw path to the file/ app/ folder etc…
“theFile” = the posix-style path to the item that many commands will need to reference the item.

Good luck…
j

Thank you so much! Worked perfectly the first time even though it was a normal AppleScript application. Again, thank you so much for you help

Many thanks,
~Balthamos

One more thing to keep in mind is that if you don’t something to inadvertently replace your object, be sure to connect an empty “on conclude drop” handler for the same object as your “on drop” handler.

For example, most Cocoa objects like an NSTextView, NSImageView, NSTextField, etc. all have built-in support for handling the drag and drop of images or text onto them and will change their contents to reflect what was dragged.

For instance, say you have an NSImageView that has an image that says “Drag your files here”. If you don’t connect an empty “on conclude drop” handler to that image view, when a user drags an image file, the image view will intercept the image before it even reaches your handler, and it may replace your image with theirs.

Hope this helps…