ImageView Location

Hey Everyone:

I have a quick question and can’t seem to find the answer by searching. I simply need to get the path of the an image what was dragged onto an image view.

Right now, I have it loading the image. They are supposed to go the next step where I would read the information about the image that was dragged.

Currently Using this for when it is dragged:

on drop theObject drag info dragInfo
	set dataTypes to types of pasteboard of dragInfo
	
	-- Currently, we are only interested if there are "files names" on the pasteboard
	if "file names" is in dataTypes then
		-- This is a mechanism to tell the pasteboard which type of data we want when we access the "contents" of the pasteboard.
		set preferred type of pasteboard of dragInfo to "file names"
		
		-- Get the list of files dropped on the object form the pasteboard
		set thePaths to contents of pasteboard of dragInfo
		
		-- Load the image at the location of the first item
		set theImage to load image (item 1 of thePaths)
		
		-- Set the image into the image view
		set image of theObject to theImage
		
		-- Make sure to delete the image we loaded otherwise it will never be removed from memory.
		delete theImage
		
		-- Set the preferred type back to the default
		set preferred type of pasteboard of dragInfo to ""
	end if
end drop

But need to get the path of the file ?

Thanks

Maybe I’m missing something obvious, but it seems you already have the path you seek:


		-- Load the image at the location of the first item
		set theImage to load image (item 1 of thePaths)

Can’t you just save that first item’s path in a variable/property?

You are very correct. My original post was confusing, even after I re-read it, I apologize for that.

What I am really looking for is to get multiple file paths. For example:

My interface as four image views, I need to capture the path for each image dropped. They are dropped individually:

http://www.onsra.net/interface.png

I am using this applescript to capture the path when the image is dragged:

on drop theObject drag info dragInfo
	set dataTypes to types of pasteboard of dragInfo
	
	-- Currently, we are only interested if there are "files names" on the pasteboard
	if "file names" is in dataTypes then
		-- This is a mechanism to tell the pasteboard which type of data we want when we access the "contents" of the pasteboard.
		set preferred type of pasteboard of dragInfo to "file names"
		
		-- Get the list of files dropped on the object form the pasteboard
		set thePaths to contents of pasteboard of dragInfo
		set thePaths2 to contents of pasteboard of dragInfo as text
		
		-- Load the image at the location of the first item
		set theImage to load image (item 1 of thePaths)
		
		-- Set the image into the image view
		set image of theObject to theImage
		
		-- Make sure to delete the image we loaded otherwise it will never be removed from memory.
		delete theImage
		
		-- Set the preferred type back to the default
		set preferred type of pasteboard of dragInfo to ""
	end if
end drop

I can set a property and populate it with one value, but I need to capture the other 3 if they are used.

Thanks,

Since you have a finite number of image views, you could detect which image view was dropped on, and then store the path in a corresponding property…

property imageView1Path : ""
property imageView2Path : ""
property imageView3Path : ""
property imageView4Path : ""

on drop theObject drag info dragInfo
	set dataTypes to types of pasteboard of dragInfo
   
	-- Currently, we are only interested if there are "files names" on the pasteboard
	if "file names" is in dataTypes then
		-- This is a mechanism to tell the pasteboard which type of data we want when we access the "contents" of the pasteboard.
		set preferred type of pasteboard of dragInfo to "file names"
       
		-- Get the list of files dropped on the object form the pasteboard
		set thePaths to contents of pasteboard of dragInfo
		set thePaths2 to contents of pasteboard of dragInfo as text

		-- Get the path of the image
		set theImagePath to (item 1 of thePaths) as text

		-- Load the image at the location of the first item
		set theImage to load image theImagePath
       
		-- Save the path
		if name of theObject is "imageView1" then
			set imageView1Path to theImagePath
		else if name of theObject is "imageView2" then
			set imageView2Path to theImagePath
		else if name of theObject is "imageView3" then
			set imageView3Path to theImagePath
		else if name of theObject is "imageView4" then
			set imageView4Path to theImagePath
		end if

		-- Set the image into the image view
		set image of theObject to theImage
       
		-- Make sure to delete the image we loaded otherwise it will never be removed from memory.
		delete theImage
       
		-- Set the preferred type back to the default
		set preferred type of pasteboard of dragInfo to ""
	end if
end drop