on open filepath problem

I’m trying to write a droplet that will create .tar files. I need to get the path of the file being dropped and am having trouble. I know this is going to be an easy answer but I can’t get it. Here is the basics I have now.

on open TheFiles
	repeat with a_file in TheFiles
		set ThePath to the path of a_file
		display dialog ThePath
	end repeat
end open

Any help would be great. Thanks.

-Cy

This might work:

on open TheFiles
	repeat with a_file in TheFiles
		set ThePath to (a_file as Unicode text)
		display dialog ThePath
	end repeat
end open

– Rob

Works like a champ! Thank you.

To modify Rob’s solution so that you’ll get a slash delimited path you can use POSIX path…

http://scriptbuilders.net


[This script was automatically tagged for color coded syntax by Script to Markup Code]

Hi,

Is it possible to get the only path to the folder of the file dropped on the app.??

Sure it’s possible – try a search for “container” on this BBS for more info…

[This script was automatically tagged for color coded syntax by Script to Markup Code]

Hi Greggo,

Thanks for reply!!

When I use your script as an app and I drop some files on it, The result is the path to my desktop.
I will search BBS for container

Thanks

bert

To get the parent folders of items dropped on a droplet, try this code:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Thanks!

It works, but - I hesitate to ask - In the script i used there is some code from Apple wich make a distinction between folders and files. So I can drop a folder with files on it and with an handler it performs some action or i can drop files on it and it performs the same action. With the above script - wich working very well for files - a folder dropped on it make’s the proces a bit complex. Because the action involved is an converter an the converted files are saved in the container of the dropped folder. And thats the parent of the folder.
So for files dropped on it, works like a champ, but an folder with files goes a little wrong.


-- This droplet processes both files or folders of files dropped onto the applet 
on open these_items
		repeat with i from 1 to the count of these_items
		set this_item to (item i of these_items)
		
		set the item_info to info for this_item
		if folder of the item_info is true then
			process_folder(this_item)
		else if (alias of the item_info is false and the file type of the item_info is in the type_list) or (the name extension of the item_info is in the extension_list) then
			process_item(this_item)
		end if
	end repeat
	tell application "TextEdit"
		quit
	end tell
	
end open

-- this sub-routine processes folders 
on process_folder(this_folder)
	
	set these_items to list folder this_folder without invisibles
	repeat with i from 1 to the count of these_items
		set this_item to alias ((this_folder as text) & (item i of these_items))
		set the item_info to info for this_item
		if folder of the item_info is true then
			process_folder(this_item)
		else if (alias of the item_info is false and the file type of the item_info is in the type_list) or (the name extension of the item_info is in the extension_list) then
			process_item(this_item)
		end if
	end repeat
end process_folder




-- this sub-routine processes files 
on process_item(this_item)

-- perform action
end process_item