Set Files as Alias in Xcode in a Drop-Handler

Hi everybody,

I’ve got a Problem in my Script:


on drop theObject drag info dragInfo
	-- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	
	-- Get a list of the data types on the pasteboard
	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
		
	end if
	
	tell application "Finder"
		set thefile to (POSIX file of thePaths as alias)
		display dialog thefile
	end tell
	
end drop


When I try the Script, I’ve got an Error in the ‘Finder’ Part. It can’t make an alias to the File i’ve dropped. Can somebody help me?

Thank you very much

Cheers
Marth

Hi,

this comment line explains the problem
– Get the list of files dropped on the object form the pasteboard

thePaths is a list of paths

Oh, thank you! But, is it possible to make these Path into an alias?

Cheers
Marth

You can convert the list of POSIX paths into a alias list


on drop theObject drag info dragInfo
	-- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	
	-- Get a list of the data types on the pasteboard
	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
		
	end if
	
	set aliasList to {}
	repeat with aPath in thePaths
		set end of aliasList to POSIX file aPath as alias
	end repeat
end drop


Oh Thank you very much! Works perfect!