Trying to get a Mail Script Action to do more than it wants

I wrote the following code to execute each time a certain rule is met inside Mail. I want it to dump the attachment to the desktop and then for it to begin another function which will convert the attachment. The problem is, Mail seems to only execute the items inside “using terms from application ‘Mail’” and it doesn’t continue on to simply run the rest of the script. Is there something I need to do to force Mail to continue on with the functions that don’t relate to Mail?


using terms from application "Mail"
	on perform mail action with messages Attached
		set theAttachmentPath to ("Macintosh HD:Users:andy:Desktop:") as text
		tell application "Mail" to repeat with ThisAttach in Attached
			set PDF_name to text from word 1 to word 1 of (get ThisAttach's content)
			set PDF_file to theAttachmentPath & PDF_name & ".jpg"
			save first mail attachment of ThisAttach in PDF_file
		end repeat
	end perform mail action with messages
end using terms from

beginConvert()

Hi,

I had a similar problem, and solved it (trial and error and reading on forums) with two different ways (I am not sure if only one would be sufficient).
1- add on run / end run inside the using terms from loop
2- call a second script to execute ; this second script will perform whatever the mail script action doesn’t want to do

using terms from application "Mail"
on run
script.using.mail
do shell script {open application "name.of.the.second.script.saved.as.an.application"}
end run
end using terms from

Hope this helps,

Best regards
Nicolas

I think you are right. It needs to be its own function. The only issue I am having is the following line:

on perform mail action with messages Attached

I can’t enclose it in a “on run” because it gets upset about the “on perform” line right below it.

Hi,

The following script works with me :

using terms from application "Mail"
	on run	
		tell application "Mail" to set theMessages to selection
		tell me to perform mail action with messages (theMessages)
rest of the script
do shell script {open application "xxxxxxxxxx"}
	end run
end using terms from

Best regards,
Nicolas