Files in Droplet vs. regular script

Dear All:

I’ve written a script to take files and email them to myself. When I was writing the script, I was testing it by just selecting some files in the Finder and then telling the script to get the selection from the Finder. The resulting script is this, and it works perfectly (NB: I’ve taken out my email address. If you want to test it, just supply one of your own).


tell application "Finder"
	set fileList to selection
end tell

tell application "Mail"
	set subjectLine to "From MacBook: "
	set currentMessage to (make new outgoing message)
	make new to recipient at end of to recipients of currentMessage with properties {name:"John Q. Sixpack", address:"john@doe.edu"}
	repeat with currentItem in fileList
		set currentName to name of currentItem
		set currentFile to currentItem as alias
		set subjectLine to subjectLine & currentName & "  |  "
		tell content of currentMessage
			make new attachment with properties {file name:currentFile} at after last paragraph
		end tell
	end repeat
	set subject of currentMessage to subjectLine
	send currentMessage
end tell

Then I wanted to turn the whole thing into a droplet, so I just added a first and last line, giving me this.


on open fileList
	tell application "Finder"
		set subjectLine to "From MacBook: "
	end tell
	
	tell application "Mail"
		set currentMessage to (make new outgoing message)
		make new to recipient at end of to recipients of currentMessage with properties {name:"J. Sixpack", address:"john@doe.edu"}
		repeat with currentItem in fileList
			set currentName to name of currentItem
			set currentFile to currentItem as alias
			set subjectLine to subjectLine & currentName & "  |  "
			tell content of currentMessage
				make new attachment with properties {file name:currentFile} at after last paragraph
			end tell
		end repeat
		set subject of currentMessage to subjectLine
		send currentMessage
	end tell
end open

But this script generates an error, to wit: Can’t make name of alias “[alias of first file]” of application “Mail” into type reference.

Does anybody have thoughts about why this is happening, and what I can do about it?

Thanks,
Bernhard.

Hi Bernhard,

the list you get with open files is a list of aliases
however the list you get with selection is a list of file references,
which behave differently

this should do it

...
repeat with currentItem in fileList
		set subjectLine to subjectLine & name of (info for currentItem) & " | "
		tell content of currentMessage
			make new attachment with properties {file name:currentItem} at after last paragraph
		end tell
	end repeat
...

Stefan:

thanks a lot. That did it. Learn something new every day.

Bernhard.