Title: Re: Entourage AppleScript for the "Rules" option [LONG SCRIPT]
On or near 12/8/00 7:22 AM, Alex Bottinelli at [EMAIL PROTECTED] observed:
> Hello...
>
> I have been looking at ftp://ftp.macemail.com/oe/Save_as_OE_Message_File.hqx
> and ftp://ftp.macemail.com/oe/Save_Selection_Message.hqx. I'm trying to
> create a script that can be set up in the "Rules" to automatically take
> incoming messages and append them to a single text file (or multiple text
> files named automatically). I am not very familiar with AppleScript tho I'm
> trying to learn. Problems with these files is that they don't actually save
> the message, it only saves a blank document (because nothing is selected I
> think), and also, it puts up a save as dialog box, and since this needs to
> be unattended, it has to save the file itself WITHOUT a dialog box.
>
> I would appreciate any help received in this matter... I'm banging my head
> against a wall here. Thanks in advance.
What follows is a quick modification of an older script. It will save any selected messages as individual Simple Text files (see the comments to change to use BBEdit or Tex-Edit or even Entourage files).
You also need to edit the script to define what folder you want the messages stored in. As it stands, it will alert you with a dialog box when it saves a file. You can delete that line if you don’t want the alert.
If assigned via an incoming mail Rule, it will save the incoming message. I’ve called the script: “Save as text file w/o prompt”.
-- Script from a message sent by Jim Baskins
-- on Monday, October 9, 2000 1:13:51 PM
(* Customizing. You can change the location where files are stored by editing
the "writeFile" handler below as follows:
set p to path to desktop folder as string
-- To specify a particular folder other than the Desktop, replace the
-- line above with something like this, using your own names:
-- set p to "MyDisk:Documents:Saved Mail:"
Also, to make the TEXT files created belong to a different creator, change
the first "set" line of the script to select a different application name from the "Creators" list. The script will pick the correct Creator Code for you.
*)
property Creatorcodes : {"ttxt", "TBB6", "R*ch", "OPIM"}
property Creators : {"Simple Text", "Tex-Edit Plus", "BBEdit", "Microsoft Entourage"}
global ccode, tcode
-- If you edit the lists above, make sure Creatorcodes and Creators match.
set theCreator to "Simple Text"
set idx to OffsetInList(theCreator, Creators)
if (idx < 1) or (idx > (count Creators)) then error "Internal Error, creator name not found: " & theCreator
set ccode to item idx of Creatorcodes
set tcode to "TEXT"
tell application "Microsoft Entourage"
activate
try
set cm to current messages
if cm is equal to {} then error "No messages selected."
set msgCount to 0
repeat with aMsg in cm
set t to source of aMsg
set sub to subject of aMsg
tell me to writefile(t, sub)
set msgCount to msgCount + 1
activate
end repeat
if msgCount = 1 then
display dialog "Message \"" & sub & "\" saved to disk."
else
display dialog "" & msgCount & " message(s) saved to disk."
end if
on error theErr
display dialog theErr
end try
end tell
on OffsetInList(theItem, theList)
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set theText to theList as text
set AppleScript's text item delimiters to tid
set theCharOffset to offset of theItem in theText
set theParOffset to count of paragraphs in (characters 1 thru theCharOffset of theText as text)
return theParOffset
end OffsetInList
on writefile(s, subj)
try
tell application "Finder" to activate
set p to path to desktop folder as string
-- To specify a particular folder other than the Desktop, replace the
-- line above with something like this, using your own names:
-- set p to "MyDisk:Documents:Saved Mail:"
set fn to makeName(subj)
set fileref to open for access (file (p & fn)) with write permission
write s to fileref
close access fileref
tell application "Finder"
activate
set the file type of file (p & fn) to tcode
set the creator type of file (p & fn) to ccode
end tell
on error theErr
display dialog theErr
end try
end writefile
on makeName(str)
try
set str to remove(":", str)
set str to remove("/", str)
if ((count str) > 31) then set str to text 1 thru 31 of str
set p to path to desktop folder as string
set nameOK to testFile(p & str)
if not nameOK then
set str to text 1 thru -3 of str
repeat with i from 1 to 99
set newstr to str & i
set nameOK to testFile(p & newstr)
if nameOK then exit repeat
end repeat
set str to newstr
end if
set temp to str
return temp
on error theErr
display dialog theErr
end try
end makeName
on testFile(aPath)
-- See if file exists
set nameOK to false
try
get file (aPath)
on error
set nameOK to true
end try
return nameOK
end testFile
on remove(char, str)
-- remove all char from str
set od to AppleScript's text item delimiters
set AppleScript's text item delimiters to char
set temp to text items of str
set AppleScript's text item delimiters to ""
set temp to temp as text
set AppleScript's text item delimiters to od
return temp
end remove
--
Peace,
Allen Watson <[EMAIL PROTECTED]> XNS name: =Allen Watson
A Mac family since 1984 <http://home.earthlink.net/~allenwatson/>
Applescripts for Outlook Express and Entourage: <http://homepage.mac.com/allenwatson/>
- Entourage AppleScript for the "Rules" option Alex Bottinelli
- Re: Entourage AppleScript for the "Rules" o... Allen Watson
- Re: Entourage AppleScript for the "Rules&quo... George Clark
