file path type or format incorrect

advice:

if download() is called from within the mail function, it runs fine,
if download() is called from check_filename() function, it does not run.

do i have a filename in the wrong format?


using terms from application "Mail"
	on perform mail action with messages theMessages
		repeat with thisMail in theMessages
			tell thisMail
				set the_subject to get subject
				set the_sender to get sender
				set the_body to (source of thisMail as text)
			end tell
			-- display dialog the_body
		end repeat
		set the_info to the_body
		set AppleScript's text item delimiters to {"**"}
		set the_info to second text item of (the_info as string)
		set AppleScript's text item delimiters to {"|"}
		set the_name to first text item of (the_info as string)
		set the_email to second text item of (the_info as string)
		set the_image to third text item of (the_info as string)
		set the_newimage to third text item of (the_info as string)
		-- display dialog the_name & " " & the_image
		-- download(the_image, the_newimage)
		check_filename(the_image, the_newimage)
		-- upload(the_image)
		comments(the_name, the_email, the_image)
	end perform mail action with messages
end using terms from

property the_path : "Alaska:Users:sl:Desktop:EH:"

on check_filename(the_image, the_newimage)
	display dialog "checking"
	set the_imagepath to the_path & the_image
	tell application "Finder"
		repeat
			if not (file the_imagepath exists) then
				display dialog "download"
				download(the_image, the_newimage)
			else
				display dialog "else"
				set AppleScript's text item delimiters to "."
				set BaseFilename to text item 1 of the_image
				set FileExt to text item 2 of the_image
				set DateStamp to do shell script "date +%m%d%y" --You may want to remove '_%y' 
				set the_newimage to text BaseFilename & "_" & DateStamp & "." & FileExt
				set the_imagepath to the_path & the_newimage
			end if
		end repeat
	end tell
end check_filename


The download() statement in the check_filename() handler is wrapped in a Finder tell block. Finder doesn’t know about your custom handlers - but your script should. So, from within an application tell block, you need to specify that a handler belongs to the script. Try using something like ‘download() of me’, or ‘my download()’.

i will try your suggestions, in the meantime, i was trying this (no Finder),
but same thing. it won’t run the do shell once the name is altered.


on check_filename(the_image, the_newimage)
	display dialog "checking"
	set p_path to POSIX path of the_path
	set file_existence to do shell script "ls " & p_path & "|grep -c " & the_newimage
	
	repeat while file_existence is greater than 0
		set AppleScript's text item delimiters to "."
		set BaseFilename to text item 1 of the_newimage
		set FileExt to text item 2 of the_newimage
		set DateStamp to do shell script "date +%m%d%y" --You may want to remove '_%y' 
		set the_newimage to BaseFilename & "_" & DateStamp & "." & FileExt
		display dialog the_newimage
             --this do shell won't run
		set file_existence to do shell script "ls " & p_path & "|grep -c " & the_newimage
		display dialog file_existence
	end repeat
	
	display dialog "download"
	download(the_image, the_newimage)
	
end check_filename


kai, i got something that works. i’ll post it for other to use under another heading.

thanks for the tips on my download().