Mail Rule help

Hi

I am having real trouble trying to get a mail rule script to work. It seems the handler on performing mail action and the using terms from mail have some unusual behaviour.
It ignores my load script command and refuses to compile when I put a run script in.
The script need to be able to process image files and ftp them to a location. I can get the script to to extract the informayion required but it then refuses to complete the processing side. I have a standalone script that will complete my request once the message is highlighted but the mail rule refuses to work
Any ideas please

Please post your script.

Thank you adayzdone

The script below works perfectly when a message is selected but when encased with

using terms from application “Mail”
on perform mail action with messages these_messages for rule this_rule

it does not process the images. I have got it as far as searching the Filemaker database but it refuses to then copy the found image to another folder. Also I have had to copy out the handlers from my script libary’s as it did not appear to load scripts properly.


property clientdata : "Client_Data_1"
property clientdatalayout : "Client_Data"
property orderlist : "order list"
property retouch : "Retouching"
property orders : "Orders"
property deletelist : {"	", "¢", "	"}
property underscore : 2
set filestuff to load script alias "Whopper:Users:johnclark:Library:Scripts:Library:FilemakerStuff.scpt"
set textstuff to load script alias "Whopper:Users:johnclark:Library:Scripts:Library:textManipulation.scpt"
set filestuff1 to load script alias "Whopper:Users:johnclark:Library:Scripts:Library:FilemakerStuff1.scpt"
set finderStuff to load script alias "Whopper:Users:johnclark:Library:Scripts:Library:FinderStuff.scpt"
set tempFolder to alias "Whopper:Users:johnclark:Library:Temp Items:"


tell application "Mail"
	--set these_messages to selection
	set the message_count to the count of these_messages
	repeat with i from 1 to the message_count
		set this_image to {}
		set this_message to item i of these_messages
		
		set thecontent to content of this_message
		set splitcontent to paragraphs of thecontent
		set splitcontent2 to words of thecontent
		
		repeat with i from 1 to number of items in splitcontent
			set this_item to item i of splitcontent
			
			set underscoreCount to 0
			if this_item contains "_" then
				set textItemlist to every text item of this_item
				repeat with i from 1 to number of items in textItemlist
					set this_char to item i of textItemlist
					if this_char is equal to "_" then
						set underscoreCount to underscoreCount + 1
						if underscoreCount is equal to underscore then
							set thisLine to this_item
							try
								set extractFile to textstuff's deleteSpace(thisLine, deletelist)
								set wordlist to words of extractFile
								set theFile to item 1 of wordlist
								set the end of this_image to theFile
								
							on error
								set the end of this_image to thisLine
								
							end try
						end if
					end if
				end repeat
			end if
		end repeat
	
		
	end repeat
end tell




--set newlist to textstuff's checkthis_image(this_image)

--Find Filemaker record

set clientID to text items -6 thru end of item 1 of this_image as string
set colorType to item 14 of splitcontent2
set downloadList to {clientID, this_image as string, colorType}


tell application "FileMaker Pro Advanced"
	
	go to database clientdata
	go to layout clientdatalayout
	show every record of database clientdata
end tell

filestuff's returnRecords(clientdata, clientdatalayout, clientID, "client_id")
--get filemaker record and image path
tell application "FileMaker Pro Advanced"
	go to database clientdata
	go to layout clientdatalayout
	set thePath to cell "path" of current record
	set thePath to (thePath & "Original Files:" & this_image & ".jpg" as string)
end tell
--copy images and process

finderStuff's duplicatefile(thePath, tempFolder)
if colorType is equal to "black" then
	tell application "Adobe Photoshop CS6"
		open file thePath
		set curDoc to current document
		set docName to name of current document
		my convertGreyscaleRGB(curDoc)
		set myOptions to {class:JPEG save options, quality:3}
		save current document in (tempFolder & docName as string) as JPEG with options myOptions
		close current document
	end tell
	tell application "Finder"
		
		set theName to name of alias (tempFolder & docName as string)
		set ext to name extension of alias (tempFolder & docName as string)
		set namenoEXT to my trimEXT(theName)
		set name of alias (tempFolder & docName as string) to (namenoEXT & "_1." & ext as string)
		move entire contents of tempFolder to alias "Whopper:Users:johnclark:PhotoData:UPLOAD TO RETOUCH FOLDER:"
	end tell
else
	tell application "Adobe Photoshop CS6"
		open file thePath
		set curDoc to current document
		set docName to name of current document
		set myOptions to {class:JPEG save options, quality:3}
		save current document in (tempFolder & docName as string) as JPEG with options myOptions
		close current document
	end tell
	
	tell application "Finder"
		move entire contents of tempFolder to alias "Whopper:Users:johnclark:PhotoData:UPLOAD TO RETOUCH FOLDER:" with replacing
	end tell
	
end if


on trimEXT(theText)
	set the trimmed_name to text 1 thru -((3) + 2) of the theText
end trimEXT
on convertGreyscaleRGB(curDoc)
	tell application "Adobe Photoshop CS6"
		set curDoc to current document
		adjust current layer of the curDoc using desaturate
		set layername to the name of the (duplicate current layer of the curDoc) as string
		
		filter art layer 1 of the curDoc using high pass with options {class:high pass, radius:3}
		set blend mode of art layer 1 of the curDoc to overlay
		set opacity of art layer 1 of the curDoc to 38
		adjust art layer 1 of the curDoc using brightness and contrast with options {class:adjustment options, brightness level:0, contrast level:35}
		--filter art layer 1 of the curDoc using unsharp mask with options {class:filter options, amount:76, radius:1.7, threshold:1}
		flatten current document
		adjust current layer of the curDoc using curves with options {class:curves, curve points:{{0, 0}, {101, 129}, {255, 255}}}
		adjust current layer of the curDoc using automatic levels
		change mode current document to grayscale
	end tell
end convertGreyscaleRGB