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

Re: Access Message Draft Window in Applescript by Mickey

Mickey
Fri May 14 18:58:31 CDT 2004

On 5/14/04 6:26 PM, in article ulE0vsgOEHA.1616@TK2MSFTNGP12.phx.gbl, "Auri
Rahimzadeh" <auri@rahimzadeh.com> wrote:

> 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!

> -- open the new message we just created
> open newMessage
>
> end tell

--
Mickey Stevens (Microsoft MVP for Office:mac)
PowerPoint FAQ featuring PowerPoint:mac: <http://www.pptfaq.com/>
Entourage Help Page: <http://www.entourage.mvps.org/toc.html>


Re: Access Message Draft Window in Applescript by Auri

Auri
Fri May 14 21:40:06 CDT 2004

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

Mickey Stevens wrote:

> On 5/14/04 6:26 PM, in article ulE0vsgOEHA.1616@TK2MSFTNGP12.phx.gbl, "Auri
> Rahimzadeh" <auri@rahimzadeh.com> wrote:
>
>
>>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!
>
>
>>-- open the new message we just created
>>open newMessage
>>
>>end tell
>
>

Re: Access Message Draft Window in Applescript by Auri

Auri
Fri May 14 23:21:01 CDT 2004

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

Re: Access Message Draft Window in Applescript by Paul

Paul
Fri May 14 23:42:14 CDT 2004

> This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

--B_3167415734_2928848
Content-type: text/plain;
charset="ISO-8859-1"
Content-transfer-encoding: 8bit


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.


> From: Auri Rahimzadeh <auri@rahimzadeh.com>
> Newsgroups: microsoft.public.mac.office.entourage
> Date: Fri, 14 May 2004 18:26:12 -0500
> Subject: Access Message Draft Window in Applescript
>
> 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


--B_3167415734_2928848
Content-type: text/html;
charset="ISO-8859-1"
Content-transfer-encoding: quoted-printable

<HTML>
<HEAD>
<TITLE>Re: Access Message Draft Window in Applescript</TITLE>
</HEAD>
<BODY>
<FONT FACE=3D"Verdana, Helvetica, Arial"><SPAN STYLE=3D'font-size:12.0px'><BR>
&nbsp;&nbsp;&nbsp;&nbsp;set currentMessage to the draft window<BR>
<BR>
doesn't make any sense. You have to specify _which_ window. And if there is=
n't one &nbsp;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 categ=
ory property so you can't get the category &quot;specs&quot;. 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.)<BR>
<BR>
This will work:<BR>
<BR>
tell application &quot;Microsoft Entourage&quot;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;display dialog &quot;Done with part 1&quot; with ic=
on 1<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;-- get the message we're working on into a variable=
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;set currentMessage to window 1<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;-- if there is no message to duplicate, warn the us=
er and then quit<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if class of currentMessage &#8800; draft window the=
n<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;display dialog &quot;Sorry,=
there is no message for me to duplicate. Waah!&quot; with icon 1<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return<BR>
&nbsp;&nbsp;&nbsp;&nbsp;end if<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;-- grab the data from the message draft window &nbs=
p;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;set theSubject to (subject of currentMessage)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;set theContent to (content of currentMessage)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;-- create a new message with the information from t=
he current message<BR>
&nbsp;&nbsp;&nbsp;&nbsp;set newMessage to make new outgoing message with pr=
operties {subject:theSubject, content:theContent} <BR>
&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;-- open the new message we just created<BR>
&nbsp;&nbsp;&nbsp;&nbsp;open newMessage<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<BR>
end tell<BR>
<BR>
<BR>
-----------------------<BR>
<BR>
Here's a version that will include the category. You have to save the draft=
window. then get the 'displayed message' of that window.<BR>
<BR>
<BR>
<FONT COLOR=3D"#0000FF"><B>tell</B></FONT> <FONT COLOR=3D"#0000FF">application<=
/FONT> &quot;Microsoft Entourage&quot;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<FONT COLOR=3D"#0000FF">display dialog</FONT> &quot;D=
one with part 1&quot; <FONT COLOR=3D"#0000FF">with icon</FONT> 1<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;--<FONT COLOR=3D"#4C4D4D"><I> get the message we're w=
orking on into a variable<BR>
</I></FONT> &nbsp;&nbsp;&nbsp;<FONT COLOR=3D"#0000FF"><B>set</B></FONT> <FONT=
COLOR=3D"#408000">frontWindow</FONT> <FONT COLOR=3D"#0000FF"><B>to</B></FONT> <=
FONT COLOR=3D"#0000FF">window</FONT> 1<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;--<FONT COLOR=3D"#4C4D4D"><I> if there is no message =
to duplicate, warn the user and then quit<BR>
</I></FONT> &nbsp;&nbsp;&nbsp;<FONT COLOR=3D"#0000FF"><B>if</B></FONT> <FONT =
COLOR=3D"#0000FF">class</FONT> <FONT COLOR=3D"#0000FF"><B>of</B></FONT> <FONT CO=
LOR=3D"#408000">frontWindow</FONT> &#8800; <FONT COLOR=3D"#0000FF">draft window<=
/FONT> <FONT COLOR=3D"#0000FF"><B>then<BR>
</B></FONT> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT COLOR=3D"#0000FF"=
>display dialog</FONT> &quot;Sorry, there is no message window for me to dup=
licate. Waah!&quot; <FONT COLOR=3D"#0000FF">with icon</FONT> 1<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT COLOR=3D"#0000FF"><B>re=
turn<BR>
</B></FONT> &nbsp;&nbsp;&nbsp;<FONT COLOR=3D"#0000FF"><B>end</B></FONT> <FONT=
COLOR=3D"#0000FF"><B>if<BR>
</B></FONT> &nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<FONT COLOR=3D"#0000FF">save</FONT> <FONT COLOR=3D"#408=
000">frontWindow<BR>
</FONT> &nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<FONT COLOR=3D"#0000FF"><B>set</B></FONT> <FONT COLOR=
=3D"#408000">currentMessage</FONT> <FONT COLOR=3D"#0000FF"><B>to</B></FONT> <FON=
T COLOR=3D"#0000FF">displayed message</FONT> <FONT COLOR=3D"#0000FF"><B>of</B></=
FONT> <FONT COLOR=3D"#408000">frontWindow<BR>
</FONT> &nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;--<FONT COLOR=3D"#4C4D4D"><I> grab the data from the =
message draft window &nbsp;&nbsp;&nbsp;<BR>
</I></FONT> &nbsp;&nbsp;&nbsp;<FONT COLOR=3D"#0000FF"><B>set</B></FONT> <FONT=
COLOR=3D"#408000">theSubject</FONT> <FONT COLOR=3D"#0000FF"><B>to</B></FONT> (<=
FONT COLOR=3D"#0000FF">subject</FONT> <FONT COLOR=3D"#0000FF"><B>of</B></FONT> <=
FONT COLOR=3D"#408000">currentMessage</FONT>)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<FONT COLOR=3D"#0000FF"><B>set</B></FONT> <FONT COLOR=
=3D"#408000">theCategory</FONT> <FONT COLOR=3D"#0000FF"><B>to</B></FONT> (<FONT =
COLOR=3D"#0000FF">category</FONT> <FONT COLOR=3D"#0000FF"><B>of</B></FONT> <FONT=
COLOR=3D"#408000">currentMessage</FONT>)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<FONT COLOR=3D"#0000FF"><B>set</B></FONT> <FONT COLOR=
=3D"#408000">theContent</FONT> <FONT COLOR=3D"#0000FF"><B>to</B></FONT> (<FONT C=
OLOR=3D"#0000FF">content</FONT> <FONT COLOR=3D"#0000FF"><B>of</B></FONT> <FONT C=
OLOR=3D"#408000">currentMessage</FONT>)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;--<FONT COLOR=3D"#4C4D4D"><I> create a new message wi=
th the information from the current message<BR>
</I></FONT> &nbsp;&nbsp;&nbsp;<FONT COLOR=3D"#0000FF"><B>set</B></FONT> <FONT=
COLOR=3D"#408000">newMessage</FONT> <FONT COLOR=3D"#0000FF"><B>to</B></FONT> <F=
ONT COLOR=3D"#0000FF">make</FONT> <FONT COLOR=3D"#0000FF">new</FONT> <FONT COLOR=
=3D"#0000FF">outgoing message</FONT> <FONT COLOR=3D"#0000FF">with properties</FO=
NT> {<FONT COLOR=3D"#0000FF">subject</FONT>:<FONT COLOR=3D"#408000">theSubject</=
FONT>, <FONT COLOR=3D"#0000FF">content</FONT>:<FONT COLOR=3D"#408000">theContent=
</FONT>, <FONT COLOR=3D"#0000FF">category</FONT>:<FONT COLOR=3D"#408000">theCate=
gory</FONT>}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;--<FONT COLOR=3D"#4C4D4D"><I> open the new message we=
just created<BR>
</I></FONT> &nbsp;&nbsp;&nbsp;<FONT COLOR=3D"#0000FF">open</FONT> <FONT COLOR=
=3D"#408000">newMessage<BR>
</FONT> &nbsp;&nbsp;&nbsp;<BR>
<FONT COLOR=3D"#0000FF"><B>end</B></FONT> <FONT COLOR=3D"#0000FF"><B>tell<BR>
</B></FONT><BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
-- <BR>
Paul Berkowitz<BR>
MVP Entourage<BR>
Entourage FAQ Page: <a href=3D"http://www.entourage.mvps.org/toc.html">&lt;ht=
tp://www.entourage.mvps.org/toc.html&gt;</a><BR>
AppleScripts for Entourage: <a href=3D"http://macscripter.net/scriptbuilders/=
">&lt;http://macscripter.net/scriptbuilders/&gt;</a> <BR>
<BR>
Please &quot;Reply To Newsgroup&quot; to reply to this message. Emails will=
be ignored.<BR>
<BR>
PLEASE always state which version of Entourage you are using - **2004**, X =
&nbsp;or 2001. It's often impossible to answer your questions otherwise.<BR>
<BR>
<BR>
<FONT COLOR=3D"#0000FF">&gt; From: Auri Rahimzadeh &lt;auri@rahimzadeh.com&gt=
;<BR>
&gt; Newsgroups: microsoft.public.mac.office.entourage<BR>
&gt; Date: Fri, 14 May 2004 18:26:12 -0500<BR>
&gt; Subject: Access Message Draft Window in Applescript<BR>
&gt; <BR>
&gt; I want to duplicate a mail message in Applescript... so I want to be <=
BR>
&gt; able to read the current message draft window and create a new message=
<BR>
&gt; based on its contents using an Applescript... any ideas? Here's my <BR=
>
&gt; (poor) code... The error I'm getting is &quot;Can't get subject of dra=
ft <BR>
&gt; window.&quot; and then it quits. The script *does* compile fine. Any h=
elp <BR>
&gt; would be greatly appreciated! Thanks!<BR>
&gt; <BR>
&gt; Best,<BR>
&gt; <BR>
&gt; -Auri<BR>
&gt; <BR>
&gt; tell application &quot;Microsoft Entourage&quot;<BR>
&gt; <BR>
&gt; display dialog &quot;Done with part 1&quot; with icon 1<BR>
&gt; <BR>
&gt; -- get the message we're working on into a variable<BR>
&gt; set currentMessage to the draft window<BR>
&gt; <BR>
&gt; -- if there is no message to duplicate, warn the user and then quit<BR=
>
&gt; if currentMessage is {} then<BR>
&gt; display dialog &quot;Sorry, there is no message for me to duplicate. W=
aah!&quot; <BR>
&gt; with icon 1<BR>
&gt; return<BR>
&gt; end if<BR>
&gt; <BR>
&gt; -- grab the data from the message draft window&nbsp;<BR>
&gt; set theSubject to (subject of currentMessage)<BR>
&gt; set theCategory to (category of currentMessage)<BR>
&gt; set theContent to (content of currentMessage)<BR>
&gt; <BR>
&gt; -- create a new message with the information from the current message<=
BR>
&gt; set newMessage to make new message with properties {subject:theName, <=
BR>
&gt; category:theCategory, content:theContent}<BR>
&gt; <BR>
&gt; -- open the new message we just created<BR>
&gt; open newMessage<BR>
&gt; <BR>
&gt; end tell<BR>
</FONT></SPAN></FONT>
</BODY>
</HTML>


--B_3167415734_2928848--