Drag and Drop question

Hello!

First of all I am really quite clueless when it comes to AppleScript. Most of my scripting comes from cutting and pasting from different examples I find online. I really have no idea what I am doing, so forgive me if what I so far is complete wrong. Anyways, I spent a great deal searching and found a lot of things close to what I am trying to do, but nothing exactly.

This seems like it should be pretty simple. All I want to do is have a variable that gets set to the name of the file that is dragged onto the script and then launch a shell script with that files name as an option.

For example lets say I have a unix program called animal and I have a file called dog.bin
I want to be able to drag the dog.bin file onto the script and have a shell script launch animal with dog as an option

Here is what I have so far.

on open draggeditem
set filename to name of draggeditem
do shell script “$HOME/desktop/animal -” & filename
end open

This is supposed to produce animal -dog.bin but instead I get an error that says Can’t get name of {alias "MacintoshHD:Users:bewell:Desktop:dog.bin}.

I sure this is easy and any assistance would be much appreciated.

Hi,

draggeditem is a list of aliases.
Either the Finder and System Events or the scripting addition command info for know the name of an alias.
Try this

on open draggeditem
	set filename to name of (info for item 1 of draggeditem)
	do shell script "$HOME/desktop/animal -" & filename
end open

have you tried this:

tell application finder to set filename to name of draggeditem

instead of that:

set filename to name of draggeditem

This doesn’t work either, Luke, because the result of the on open parameter is always a list,
even if there’s only one item dragged onto.

PS: scnr and it doesn’t work, because nobody knows, what application finder is ;):wink:

sorry
if {} ≠draggeditem then
tell application “Finder” to set x to name of (info for (draggeditem’s first item))
end if

That worked perfectly. Thanks so much.

if {} ≠draggeditem then the open handler will never be called :wink:

info for is part of Standard Additions; Use one or the other.

set x to name of (info for (first item of draggeditem))
 tell application "Finder" to set x to name of (first item of draggeditem)