send mail with attachment with path in body of triggering mail

Hi

I would like to send a mail with a path to a file in the body to trigger a script that sends back a mail with the file attached; the following subroutine almost :frowning: works, except for the line: set theAttachment to (path to “cusr”) & theContent as alias

theSender is the address the mail should be returned to, theContent is a string extracted from the body of the triggering mail containing the last part of the path (“Documents:docname”) to the file I want to have mailed back as an attachment

on sendattachment(theSender, theContent)
	tell application "Mail"
		activate
		try
			set theSubject to (path to "cusr") & theContent as string -- yields the correct complete path to the file
			set theAttachment to (path to "cusr") & theContent as alias -- (gives an error, can't figure out the correct syntax)
			set myMessage to make new outgoing message with properties {subject:theSubject, content:"voilà " & return}
			tell myMessage
				make new to recipient at end of to recipients with properties {address:theSender}
				tell content
				make new attachment with properties {file name:theAttachment} at after the last paragraph
				end tell
			end tell
			send myMessage
		end try
	end tell
end sendattachment

It works fine if I replace “set theAttachment to (path to “cusr”) & theContent as alias” by "set the theAttachment to (path to “cusr”) & “Documents:docname” as alias

Any ideas

TIA

Jaques:

It is not that easy, I’m afraid. Both, the original code as well as yours generate the error “File DIsk:User:Documents:docname not found” However the scripts works fine if I replace “set theAttachment to (path to “cusr”) & theContent as alias” by “set theAttachment to DIsk:User:Documents:docname”

Malheureusement, c’est pas si simple. However, I found something that works unfortunately without understanding why it works.

As mentioned, “set theContent to theContent as string” followed by “set theSubject to (path to “cusr”) & theContent as string” doesn’t work, it gives me the entire path (DIsk:User:Documents:docname) but the file won’t be found. However, if I change the script into “set theContent to the first paragraph of theContent as string” followed by “set theSubject to (path to “cusr”) & theContent as string” it works. Amazingly, I do not see any difference between the two results, when I display the result in a dialog, I see the same “DIsk:User:Documents:docname” May be there is something extra in the contents of the triggering script that is not shown but is not translated into a correct path (a return ?) which is lost when extracting the first paragraph only.