I am creating a droplet that automatically trashes the elements I drop on it, depending of their kind (files and folders are trashed, volumes are ejected).
I experienced a problem though. When I drop an “alias file” (icon with an arrow in the corner) on my script, the alias is deleted but the file it is pointing to is also deleted. When I attempt to get the alias kind using AS, it returns the kind of the original element instead of just “alias”.
I just want to know if it is possible to trash “alias files” without trashing the original file/folder in AS.
Thanks! But I don’t think your fix is the right solution to my problem. Here is the script I was talking about:
on open theFiles
set myList to {}
tell application "Finder"
repeat with i in theFiles
set theKind to kind of i
if theKind is "Volume" then
eject i
else
set the end of myList to i
end if
end repeat
move every item of myList to trash
end tell
end open
In this script, the aliases you drop on the droplet-application are trashed along with the original file. I would like to trash only the alias, not the original. In other words, I don’t want the aliases to be “resolved” during the trash process.
BTW, after testing it for many days by now, my script appears to be 100% safe in the exception that the originals are trashed along with the aliases. However, if someone (not using my script) attempts to trash a volume using your method, the result will indeed be scary… and the Finder will be forced to restart.
I posted my script because using the Finder selection does not resolve the original item from the alias, whereas trying to resolve the kind of an alias with your method (as I have found) results in other scary behavior.
But I think, at this point in the evening, I will just say ‘Oops’ and bow out gracelessly.
Using Peter Bunn’s line in your script works for me.
If it doesn’t work for you, try restarting.
on open theFiles
tell application "Finder"
repeat with i in theFiles
set theKind to kind of i
if theKind is "Volume" then
eject i
try
error
end try
else
move the selection to trash
end if
end repeat
-- empty -- optional
end tell
end open
Tom
Browser: Camino 1.6
Operating System: Mac OS X (10.4)
on open of fileList
tell application "Finder"
set volumeKind to kind of the startup disk
repeat with oneFile in fileList
if (kind of oneFile) as string is equal to volumeKind then
eject oneFile
try
error
end try
else
move the selection to trash
end if
end repeat
end tell
end open
Tom
Browser: Camino 1.6
Operating System: Mac OS X (10.4)
When an alias file’s dragged onto a droplet, it’s the original item that appears in the parameter list the droplet receives (theFiles in your case), not the alias file itself. This is automatic and correct because the implication of dragging an alias file onto an application is that you want the application to do something with the original. Your script only ever sees the original item.
If you want a droplet to work on an actual alias file, the only hope is Peter’s suggestion of ignoring the parameter list and using the Finder’s selection. The theory is that user will have selected the item(s) in order to drag them onto the droplet. But this isn’t reliable, as it’s conceivable that the Finder’s selection might change between the time of the drop and the time the script reaches the relevant line, or the items might have been dragged from some other application, or the droplet may simply have been activated by an open command. Really, it’s best not to use droplets to handle alias files.
You helped me quite a bit. But it would be a good idea to remember what Peter said first, because it is really important with this kind of manipulation: