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
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