Mail rule not executing

I am trying to make a rule, that when a piece of mail of a certain title comes in, a rule gets executed to open the attachment in Neatworks. It runs fine if the mail is selected and the rule is triggered. When the piece of mail first comes in though, the rule terminates before opening in Neatworks.

Below is a slightly modified script. The attachment opens in Preview instead of Neatworks to eliminate that as a potential problem.

Someone see something wrong with this?


using terms from application "Mail"
	on perform mail action with messages theMessages
		tell application "Finder" to set pathToAttachments to (path to desktop folder as string)
		tell application "Mail"
			repeat with theMessage in theMessages
				if theMessage's mail attachments is not {} then
					repeat with theAttachment in theMessage's mail attachments
						set theFileName to pathToAttachments & (theMessage's id as string) & space & theAttachment's name
						try
							save theAttachment in theFileName
						on error errnum
						end try
					end repeat
				end if
				tell application "Preview" to open theFileName
				tell application "Finder" to delete theFileName
			end repeat
		end tell
	end perform mail action with messages
end using terms from


What version of OS X are you running? For Lion and Snow Leopard the save command in Mail was broken.