Access Message Draft Window in Applescript

A

Auri Rahimzadeh

I want to duplicate a mail message in Applescript... so I want to be
able to read the current message draft window and create a new message
based on its contents using an Applescript... any ideas? Here's my
(poor) code... The error I'm getting is "Can't get subject of draft
window." and then it quits. The script *does* compile fine. Any help
would be greatly appreciated! Thanks!

Best,

-Auri

tell application "Microsoft Entourage"

display dialog "Done with part 1" with icon 1

-- get the message we're working on into a variable
set currentMessage to the draft window

-- if there is no message to duplicate, warn the user and then quit
if currentMessage is {} then
display dialog "Sorry, there is no message for me to duplicate. Waah!"
with icon 1
return
end if

-- grab the data from the message draft window
set theSubject to (subject of currentMessage)
set theCategory to (category of currentMessage)
set theContent to (content of currentMessage)

-- create a new message with the information from the current message
set newMessage to make new message with properties {subject:theName,
category:theCategory, content:theContent}

-- open the new message we just created
open newMessage

end tell
 
M

Mickey Stevens

I want to duplicate a mail message in Applescript... so I want to be
able to read the current message draft window and create a new message
based on its contents using an Applescript... any ideas? Here's my
(poor) code... The error I'm getting is "Can't get subject of draft
window." and then it quits. The script *does* compile fine. Any help
would be greatly appreciated! Thanks!

Best,

-Auri

tell application "Microsoft Entourage"

display dialog "Done with part 1" with icon 1

-- get the message we're working on into a variable
set currentMessage to the draft window

-- if there is no message to duplicate, warn the user and then quit
if currentMessage is {} then
display dialog "Sorry, there is no message for me to duplicate. Waah!"
with icon 1
return
end if

-- grab the data from the message draft window
set theSubject to (subject of currentMessage)
set theCategory to (category of currentMessage)
set theContent to (content of currentMessage)

-- create a new message with the information from the current message
set newMessage to make new message with properties {subject:theName,
category:theCategory, content:theContent}

Change this line to
set newMessage to make new message with properties {subject:theSubject,
category:theCategory, content:theContent}

Hope this helps!
 
A

Auri Rahimzadeh

I still get the "Can't get subject of draft window." error. I get past
the "Got past part 1" messagebox...

Any ideas?

Thanks again!

Best,

-Auri
 
A

Auri Rahimzadeh

Ok, I figured it out... here's my code (you may all find it useful in
case you want to send a message to multiple recipients)...

-- Entourage Draft Message Duplication Script
-- written by Auri Rahimzadeh
-- Copyright (c) 2004 The Auri Group, LLC
-- Distribution only with permission.
-- www.WeAreIT.biz / 317-522-4092
-- tested with Microsoft Entourage 10.1.5 in OS X "Panther" 10.3.3
-- Description: Takes a draft window that is open and duplicates it
without recipients.
-- Project Started: May 14, 2004
-- Last Modified: May 14, 2004
-- History:
-- 14-May-2004: Project started. Initial version completed.

tell application "Microsoft Entourage"

activate

-- get the message we're working on into a variable
set theWindow to window 1

-- if we're working with a draft window then we're in good shape
if class of theWindow is draft window then
-- get the content of the current message
set theSubject to subject of theWindow
set theContent to content of theWindow

-- create a new message with the information from the current message
set newMessage to make new outgoing message with properties
{subject:theSubject, content:theContent}

-- open the new message we just created
open newMessage
else
-- bummer, it's not a draft window, so don't fulfill the request
display dialog "Sorry, I can only duplicate a message if it's a draft
message."
end if

end tell
 
P

Paul Berkowitz

set currentMessage to the draft window

doesn't make any sense. You have to specify _which_ window. And if there
isn't one it wouldn't be an empty list {}, it would simply error. Later on,
there's another error with categories - draft windows don't have a category
property so you can't get the category "specs". Then you have another error
where you try to use the variable 'theName' which is undefined, at least in
the part of the script you sent. Then there's another error in that you
can't make a 'new message': it has to be a new 'outgoing message'. (Assuming
that you don't simply want to make a new draft window.)

This will work:

tell application "Microsoft Entourage"

display dialog "Done with part 1" with icon 1

-- get the message we're working on into a variable
set currentMessage to window 1

-- if there is no message to duplicate, warn the user and then quit
if class of currentMessage ‚ draft window then
display dialog "Sorry, there is no message for me to duplicate.
Waah!" with icon 1
return
end if

-- grab the data from the message draft window
set theSubject to (subject of currentMessage)
set theContent to (content of currentMessage)

-- create a new message with the information from the current message
set newMessage to make new outgoing message with properties
{subject:theSubject, content:theContent}

-- open the new message we just created
open newMessage

end tell


-----------------------

Here's a version that will include the category. You have to save the draft
window. then get the 'displayed message' of that window.


tell application "Microsoft Entourage"

display dialog "Done with part 1" with icon 1

-- get the message we're working on into a variable
set frontWindow to window 1

-- if there is no message to duplicate, warn the user and then quit
if class of frontWindow ‚ draft window then
display dialog "Sorry, there is no message window for me to
duplicate. Waah!" with icon 1
return
end if

save frontWindow

set currentMessage to displayed message of frontWindow

-- grab the data from the message draft window
set theSubject to (subject of currentMessage)
set theCategory to (category of currentMessage)
set theContent to (content of currentMessage)

-- create a new message with the information from the current message
set newMessage to make new outgoing message with properties
{subject:theSubject, content:theContent, category:theCategory}

-- open the new message we just created
open newMessage

end tell








--
Paul Berkowitz
MVP Entourage
Entourage FAQ Page: <http://www.entourage.mvps.org/toc.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Entourage you are using - **2004**, X
or 2001. It's often impossible to answer your questions otherwise.
 
Top