Re: Script to Copy/Paste Entourage Message Bodies
Re: Script to Copy/Paste Entourage Message Bodies
- Subject: Re: Script to Copy/Paste Entourage Message Bodies
- From: Paul Berkowitz <email@hidden>
- Date: Tue, 25 Mar 2003 11:40:27 -0800
On 3/24/03 5:03 PM, "Ramona Rock" <email@hidden> wrote:
>
Hi there. I'm a relative newbie, and I'm desperately trying to write what I
>
thought would be a fairly simple script to take the messages out of a folder
>
which I would designate by title in Entourage, copy their message bodies (I
>
don't want the subject or any other header info), paste them into a TextEdit
>
document on my desktop, then move those messages into another folder. (My
>
original plan was to paste it into an MS Word document, but after the
>
discussion earlier today re: the difficulty in scripting MS Word, I thought
>
I'd go with TextEdit instead.)
>
>
Here is what I have so far, in part via help from Andrew on this list
>
(thanks Andrew) but I still can't get it to work. The last error I got was
>
"TextEdit got an error: document ":desktop:newstuff" doesn't understand the
>
open message."
>
>
Could someone tell me what I'm doing wrong? I'd be most appreciative!
>
Thanks! Ramona
>
>
tell application "TextEdit"
>
open document ":desktop:newstuff"
>
end tell
>
tell application "Microsoft Entourage"
>
repeat with aMessage in folder "New Stuff"
>
set theBody to content of aMessage
>
tell application "TextEdit"
>
write theBody to "newstuff"
>
end tell
>
move aMessage to folder "Archived"
>
end repeat
>
end tell
There's not much problem with your Entourage scripting. Just one. you can't:
repeat with aMessage in folder "New Stuff"
You can only use 'repeat with aSomething in' a LIST, not an Entourage
folder. First you have to
set theMessages to every message in folder "New Stuff" -- a list of
messages
Then you can
repeat with aMessage in theMessages
The problem is with your TextEdit scripting: TextEdit does not have a
'write' command. It's not anywhere in its dictionary - take a look and
you'll see. Also you should not be putting one tell block inside another
one, but that's a minor issue. Also
open document ":desktop:newstuff"
does nothing. It's not a proper file path to an existing document, and
that's why you're getting an error.
'write' is a Standard Addition that does not need any application tell
block. Check the Standard Additions dictionary in ScriptingAdditions
(/System/Library/ScriptingAdditions/). What it does need is an 'open for
access file filePath with write permission' which will make a new text file
on your disk, which you can then open in TextEdit. Or else you can try to
script TextEdit itself with its own commands. Here are the two methods. The
first method is better because I can't work out how to save a TextEdit doc
in the second method. In both cases remove the email-induced carriage
returns in the middle of long lines when pasting to Script Editor. I've
added a separator between messages.
1. To new text file, opened in TextEdit
set fileSpec to (path to desktop as string) & "newstuff"
set fileRef to open for access file fileSpec with write permission -- makes
new "newstuff" file or overwrites existing one
set eof fileRef to 0 -- clean overwrite (erases previous text)
--omit previous line to continue on without replacing
tell application "Microsoft Entourage"
set theMessages to every message in folder "New Stuff"
repeat with aMessage in theMessages
set theBody to content of aMessage as string
tell me to write (theBody & return & "---------------" & return) to
fileRef starting at ((get eof fileRef) + 1) -- one line
-- must 'tell me' because fileRef is outside Entourage
move aMessage to folder "Archived"
end repeat
end tell
close access fileRef
tell application "TextEdit"
activate
open {alias fileSpec} -- TextEdit needs a list!
end tell
-----------------------------------
2. To TextEdit doc, but i haven't figured out how to save a TextEdit doc to
a file path as it should. I always get a "type 8" error and it doesn't get
saved, although it does get named. Adding extensions and/or file types
doesn't help.
set fileSpec to (path to desktop as Unicode text) & "newstuff"
tell application "TextEdit" to set newDoc to make new document at end of
documents -- one line
set theText to ""
tell application "Microsoft Entourage"
set theMessages to every message in folder "New Stuff"
repeat with aMessage in theMessages
set theBody to content of aMessage as string
set theText to theText & (theBody & return & "---------------" &
return)
move aMessage to folder "Archived"
end repeat
end tell
tell application "TextEdit"
set text of newDoc to theText
--save newDoc in fileSpec -- can't
end tell
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.