Re: Problem with repeat command
Re: Problem with repeat command
- Subject: Re: Problem with repeat command
- From: Paul Berkowitz <email@hidden>
- Date: Wed, 26 Oct 2005 12:46:52 -0700
- Thread-topic: Problem with repeat command
On 10/26/05 11:56 AM, "francois.houle" <email@hidden> wrote:
> I'm writing a script to export mail from Entourage to Word, save the mail in
> there as a word doc in a specific location. What I'm not able to do up to
> now is to be able to select multiple pieces of mail and have all of them
> save and close in word one after the other... I tried to do it but it only
> seems to save the last item that's selected. The others, even thou windows
> open for them in word and it seems to save them, they appear nowhere on the
> computer. Don't have an idea whats wrong since I get absolutely no error
> messages when executing the script.
The script is doing exactly what you're telling it to do, so of course
there's no error. You're telling it to get the content and subject of each
Entourage message, but then you do nothing with any of that until you get to
the end. So it does it only with the last values for the variables
theContent and theName, just as tell it to do. You need to put all the Word
stuff in the same repeat loop. See below.
> Also, I've included a command to change the path to save to and change the
> default back to standard at the end... Is this the best way to do it ?
No. you can just tell it where to save the document. I'm rushing out now, so
I'll get back to this later if someone else hasn't by then. See below for
the main fix to get all documents saved. (You want them all as separate
documents, right? Not a single doc? That would be a different repeat loop,
with the saving at the end, after the repeat loop finishes. If you make it
clear which you want, I can tell you which way to do it. )
>
> So here is the script:
>
> tell application "Microsoft Entourage"
> set selectedMessages to current messages
> if selectedMessages is {} then
> display dialog "Please select a message first and then run this
> script." with icon 1
> return
> end if
> repeat with theMessage in selectedMessages
> set theName to subject of theMessage
> set theContent to content of theMessage
> end repeat
> end tell
You've just done a repeat loop getting the subject and content of each
Entourage message - but you've done absolutely nothing with any of it except
to change the value of your two variables theName and theContent over and
over again. At ten end they have the values from the last message, so that's
all that proceeds to the Word part of the script. You need to put the Word
section _inside _ the repeat loop. The best way to do that, since you're
already inside an Entourage tell block, is via a handler. Like this:
repeat with theMessage in selectedMessages
set theName to subject of theMessage
set theContent to content of theMessage
my MakeWordDoc(theName, theContent)
end repeat
end tell
to MakeWordDoc(theName, theContent)
>
> tell application "Microsoft Word"
> set default file path file path type documents path ¬
> path "Macintosh HD:Users:myuser:Documents:Entourage dump"
> repeat with theMessage in selectedMessages
> set fileName to do shell script "echo '" & theName & "' | tr
> '[:punct:]' ' '"
> set newDoc to make new document
> set name of font object of text object of newDoc to "Times New
> Roman"
> set oRange to create range active document start 0 end 0
> set content of oRange to theContent
> set oRange to change end of range oRange by a word item ¬
> extend type by selecting
> save as newDoc file name fileName
> close document theName
> end repeat
> set default file path file path type documents path ¬
> path "MacIntosh HD:Users:myuser:Documents"
> end tell
>
end MakeWordDoc
--
Paul Berkowitz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden