Download Mail attachments - AND THEN ?

So I am using a script that is triggered by a “Rule” in Mail. It works fine. The purpose is to download all attachments from a particular sender into a folder. The script looks like this:


using terms from application "Mail"
	on perform mail action with messages theMasterList
		tell application "Finder" to set pathToAttachments to ("Macintosh HD:")
		repeat with theMessage in theMasterList
			set suffix to 0
			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
					set suffix to suffix + 1
					set theFileName to theFileName & " - " & (suffix as string)
					save theAttachment in theFileName
				end try
			end repeat
		end repeat
	end perform mail action with messages
end using terms from

But I need some further processing. I want to more scripting to the end. But if i simply copy/paste the additional script language into the above script…this 2nd section of script does NOT run. How can I make it work? Just so you know, here’s the additional scripting that I want to combine with the above script…

tell application "Finder"
	open folder "Macintosh HD:Users:kevin:Desktop:test:"
	set frontmost to true
end tell


on zeroPad(theNumber)
	set theString to ""
	if theNumber is less than 10 then set theString to "0"
	set theString to theString & theNumber
	return theString
end zeroPad

set theDate to current date
set theTime to time of theDate

set TimeValue to theTime div hours & "." & zeroPad(theTime mod hours div minutes) as string

set theDate to current date
set dayString to zeroPad((day of theDate) as integer)
set monthString to zeroPad((month of theDate) as integer)

set DateValue to monthString & dayString
set mySpot to (path to desktop as Unicode text) & "test:"

tell application "Finder"
	if exists (files of folder mySpot whose name contains "tahoe") then
		set name of (files of folder mySpot whose name contains "tahoe") to "Forecast_" & DateValue & "-" & TimeValue & ".pdf"
		
	end if
end tell