I have a problem running the same script on different machines..

Hello all,

Few months ago I got help in here to create an apple script for the application Microsoft entourage…

tell application "Finder" to set theAttachments to files in alias theAttachment whose file type is "JPEG"
tell application "Microsoft Entourage"
	set newMessage to make new outgoing message at out box folder with properties {subject:theSubject, content:theBody}
	open newMessage
	set thedraft to (first window whose class is draft window)
	repeat with i in theAttachments
		make new attachment of thedraft with properties {file:i as alias}
	end repeat
	activate
end tell

The thing is its not always working… even with the same version of entourage and the same version of Mac OS it is sometimes working and other times its not… it depends on the machine :S
when its not, either entourage crashes on some machines or the script is just not compiling on others. But what’s strange is that it works perfectly on some machines.

when it crashes… its because I’m using the property “attachment” in the class “outgoing message” on a specific machine entourage crashes and an error pops in the script editor. When its not crashing [i.e. when its on a different machine] I’m getting a mail that is created but with no attachments and an error in script editor pops and say that the window 1 of class draft window cannot be found… and on other machines its working perfectly!!

What’s going on?? what can I do??
Any help is greatly appreciated…

Thanks,
psychoed

Why don’t you…

tell application "Finder"
	set theAttachments to files in alias theAttachment whose file type is "JPEG"
	
	--> convert "finder items" (objects) to aliases, so Entourage understands what's going on:
	repeat with i from 1 to count theAttachments
		set theAttachments's item i to (theAttachments's item i) as alias
	end repeat
end tell

--> now, simply pass the list to the new msg... (no need of iteration)
tell application "Microsoft Entourage"
	set newMessage to make new outgoing message at outbox folder with properties {subject:theSubject, content:theBody, attachment:theAttachments}
	--> blah
end tell

thanks jj , for making the code clearer… but i tried this


set theSubject to "this is a test subject"
set theBody to "this is a test body"
set theAttachment to "Macintosh HD:Applications:test:"
tell application "Finder"
	set theAttachments to files in alias theAttachment whose file type is "JPEG"
	repeat with i from 1 to count theAttachments
		set theAttachments's item i to (theAttachments's item i) as alias
	end repeat
end tell
tell application "Microsoft Entourage"
	set newMessage to make new outgoing message at out box folder with properties {subject:theSubject, content:theBody, attachment:theAttachments}
end tell

on a dual 1.8 G5 with OS 10.3.9 and yet it gave me the same result… the message is beig created but no attachments are being attached…
what may be the problem?? i checked eveything including the privilages… can u please help me further…

thanks,
Psycho-ed

Seems the Finder didn’t find files whose file type is “JPEG” :smiley:

Perhaps you could try finding files -whose name extension is in {“jpg”, “jpeg”, “jpe”}-

come on jj!
i’m sure there’s pictures of type “JPRG” in that folde cz 1. i did put them…
and two i have a smililar script for the mail application that uses…

set theAttachments to files in alias theAttachment whose file type is "JPEG"

and it’s working fine :rolleyes:

psycho-ed

I am having a similar problem. I have found that a script that works fine on one machine doesn’t on another, even with the same software and OS version. Is this common with AppleScript? My issue is with Adobe Illustrator and Adobe Acrobat. The only thing I can think of (in your case and mine) is that some of the software has been setup with different defaults on each computer. For me it may be that the Acrobat Distiller has a different PPD on each machine.

Comments or thoughts anyone?
-Simpleton

Well, but this doesn’t mean the files have a “JPEG” file type (unless u’re absolutely sure, of course). What’s the result if you insert a “display dialog (count theAttachments)” before the repeat loop? I’d expect it to be “0”, since nothing is passed as attachment to Entourage… If so, what is the result of executing the following:

tell application "Finder" to ¬
	return (get file type of first file of alias theAttachment ¬
		whose name extension is in {"jpeg", "jpg", "jpe"})

Is it “JPEG” (or one of the variants), or “missing value”?

Anyway, do you have the same OS/Entourage versions in both machines?