Wow, thanks, Allen.
In case speed becomes an issue (which I'm tending to doubt), there's another solution that should take a VERY minor speed hit, but be scalable to as many messages as AS can put in a list. It simply numbers the list and uses the number rather than searching back through...
Regards,
Bryan
-- Open Template
-- script by Bryan Harris, [EMAIL PROTECTED], 30 October 2000
-- This script allows the user to select a template
-- from the "TEMPLATE" folder (at the root folder level).
tell application "Outlook Express"
activate
with timeout of 600 seconds
try
set theMsgs to (every message of folder "TEMPLATES")
on error
display dialog "Can't find a \"TEMPLATES\" folder. This script requires that there be a folder named \"TEMPLATES\" at the root folder level with messages in it to be used as templates." with icon stop
return
end try
set theCount to count of theMsgs
if theCount is 0 then
display dialog "There are no templates in the \"TEMPLATES\" folder. Please drag at least one message to that folder to use this script." with icon stop
return
end if
set theSubs to {}
repeat with i1 from 1 to theCount
set theSubs to theSubs & (i1 & ". " & subject of (item i1 of theMsgs) as string)
end repeat
set theTemp to (choose from list theSubs with prompt "Select a template:" without multiple selections allowed and empty selection allowed) as string
set i2 to ((characters 1 through ((offset of "." in theTemp) - 1) of theTemp) as string) as integer
set theSubj to (subject of item i2 of theMsgs)
set theCont to (content of item i2 of theMsgs)
make new draft window with properties {subject:theSubj, content:theCont}
end timeout
end tell
From: Allen Watson <[EMAIL PROTECTED]>
Reply-To: "Entourage:mac Talk" <[EMAIL PROTECTED]>
Date: Tue, 31 Oct 2000 09:06:17 -0700
To: "Entourage:mac Talk" <[EMAIL PROTECTED]>
Subject: Re: templates
on 10/30/2000 5:33 PM, Bryan Harris at [EMAIL PROTECTED] wrote:
> Here's a script that should do the trick. You can drop any message in the
> TEMPLATES folder and it'll work. (I'm sure someone more experienced than I
> can figure out how to choose messages from a list directly using their
> subjects rather than the search-back-through-them method I resorted to here.
> No noticeable lag, but still not a method I'm proud of using...)
>
> I don't have Entourage (still too pricey for me), so I can't try this out,
> but I hear there aren't any compatibility problems, so it should work fine.
>
> Sorry, can't help you with moving permanent folders. Changing icons might
> be possible using ResEdit, but you're treading thin ice there if you've
> never done it before.
>
> - Bryan
>
Bryan, I took a quick shot at improving your script for you. The method you used to match the list of subject to the list of messages was not bad. The method I give may seem more complicated but is actually slightly faster because it uses the internal �text items� routines instead of a repeat loop. It isn�t original with me; I learned it on the AppleScript list. Also, I replaced your loop to get the subjects with a single line. Functionally, this version does exactly what yours did, just maybe marginally faster. Probably not enough to make any difference unless you had a huge list of templates!
In a message to follow I will post a script that will open a message from a list of template TEXT files.
>
> ****************************************************************************
> Copy the following script into a Script Editor window,
> then save into your Script Menu Items folder as a compiled script.
> ****************************************************************************
on itemOffset(theString, theList)
set AppleScript's text item delimiters to {return}
-- coerce theList to a return delimited and wrapped string
set ls to return & theList & return
try
-- find the (return-wrapped) search string in the list string
-- and count the text items up to that point
set theIndex to (count text items 1 thru character �
(offset of (return & theString & return) in ls) of ls) - 1
on error
-- the search string is not in the list string
set theIndex to 0
end try
set AppleScript's text item delimiters to {""}
return theIndex
end itemOffset
-- Open Template
-- script by Bryan Harris, [EMAIL PROTECTED], 30 October 2000
-- Slight mods by Allen Watson, [EMAIL PROTECTED], 10/30/2000
-- This script allows the user to select a template
-- from the "TEMPLATE" folder (at the root folder level).
tell application "Microsoft Entourage"
activate
with timeout of 600 seconds
try
set theMsgs to (every message of folder "TEMPLATES")
on error
display dialog "Can't find a \"TEMPLATES\" folder. This script requires that there be a folder named \"TEMPLATES\" at the root folder level with messages in it to be used as templates." with icon stop
return
end try
set theCount to count of theMsgs
if theCount is 0 then
display dialog "There are no templates in the \"TEMPLATES\" folder. Please drag at least one message to that folder to use this script." with icon stop
return
end if
set theSubs to subject of every message of folder "TEMPLATES"
(*
set theSubs to {}
repeat with theMsg in theMsgs
set theSubs to theSubs & (subject of theMsg as string)
end repeat
*)
set theTemp to (choose from list theSubs with prompt "Select a template:" without multiple selections allowed and empty selection allowed) as string
-- Use subroutine to find offset of subject in subject list.
-- This assumes there are no duplicate subjects and will always find the
-- first match.
(*
set iFound to false
set i to 0
repeat until iFound
set i to i + 1
if i > theCount then
display dialog "Script error 1. Contact Bryan Harris ([EMAIL PROTECTED]) to report this." with icon stop
return
end if
if (item i of theSubs) is theTemp then set iFound to true
end repeat
*)
set i to my itemOffset(theTemp as string, theSubs)
set theSubj to (subject of item i of theMsgs)
set theCont to (content of item i of theMsgs)
make new draft window with properties {subject:theSubj, content:theCont}
end timeout
end tell
--
Peace,
Allen Watson <[EMAIL PROTECTED]> XNS name: =Allen Watson
A Mac family since 1984
My web page: <http://home.earthlink.net/~allenwatson/>
