Title: New Script - Archive to Dated Subfolders
Well, I think I have my script at a point where it is fit for consumption...

This script works on one selected folder at a time, and has a shortcut key of Command-Option-A attached to it.

It processes all messages in a folder, and creates dated subfolders below it and moves the messages into the subfolders.

For example, I started with a mail folder named Entourage Talk that had all postings from this list in it. I ran the script and wound up with something like this:

Entourage Talk
 |
 +- 2000-01
 +- 2000-02
 .
 .
 .
 +- 2001-06

The way the script is currently written, it starts in January of the previous year, and will create folders as needed, or reuse folders if they already exist.

Caveats: This is my first script. Things are probably done strange. Please point these things out to me, so that I may improve my skills. The script is very, very slow when run against large folders (>1000 messages). I ran it against a folder with over 6000 messages and it took two hours to complete.

I hope that someone may find this useful, or someone wants to help me take this to the next level.


Script:

(*********************************************************************
**    Script: Archive to Dated Subfolders
**    For application: Microsoft Entourage
**    Author: Kenneth Scott
**    Date: June 25, 2001
**    Version: 1.0
**********************************************************************
**    Future enhancements: Process on a  group of messages
**        Display progress bar during message movement
**        Performance enhancements
********************************************************************
*)

tell application "Microsoft Entourage"
    set theBaseFolder to get the selection
    if class of theBaseFolder is not folder then
       display dialog "Select a folder before running this script"
        return
   end if
   
    --
set theYear to 1996
   set theYear to (the year of the (current date)) - 1 -- Base year to start from
   set theMonth to 1 -- Setup the month before the loop
   repeat --Loop will be exited when the end date exceeds today's date
       tell me to set datestart to date ((theMonth as text) & "/1/" & (theYear as text))
        if theMonth = 12 then
           set {nextMonth, nextYear} to {1, theYear + 1}
        else
           set {nextMonth, nextYear} to {theMonth + 1, theYear}
        end if
       tell me to set dateend to ((date ((nextMonth as text) & "/1/" & (nextYear as text))) - 1) --
1 second before the start of the first of the next month
       
        --
Don't process the current month's messages
       if dateend > (current date) then exit repeat
       
        --
set msgList to ((every message of theBaseFolder) whose ((time sent � datestart) and (time sent � dateend)))
       --if (count of msgList) > 0 then
       --if (count of ((every message of theBaseFolder) whose ((time sent � datestart) and (time sent � dateend)))) > 0 then
       --open theBaseFolder
       --set the selection to msgList
       
        set theMonthText to theMonth as text
        if length of theMonthText < 2 then set theMonthText to "0" & theMonthText
        set archiveFolderName to (theYear as text) & "-" & (theMonthText)
        
        set ArchiveFolder to my getArchiveFolder(archiveFolderName, theBaseFolder)
        
        --
move msgList to newFldr
       move ((every message of theBaseFolder) whose ((time sent � datestart) and (time sent � dateend))) to ArchiveFolder
        if (count of messages in ArchiveFolder) is 0 then delete ArchiveFolder
        (*
           repeat with eachMsg in msgList
                move eachMsg to ArchiveFolder
            end repeat
            
*)
        --
end if
       set {theMonth, theYear} to {nextMonth, nextYear}
    end repeat
end
tell


on getArchiveFolder(archiveFolderName, theParent)
    --
Call example: my getArchiveFolder("2000-08", folder "Entourage Talk")
   --Use "application "Microsoft Entourage" as parent for first-level folders
   tell application "Microsoft Entourage"
        set theSubfolders to the folders of theParent
        repeat with thisSubfolder in theSubfolders
            if name of thisSubfolder is archiveFolderName then return thisSubfolder
        end repeat
       --
If we fall out of the loop then the folder name was not found. Create and return it
       set newFolder to make new folder with properties {name:archiveFolderName} at theParent
        return newFolder
    end tell
end
getArchiveFolder

=====End Script

Ken
--
<><      Ken Scott   [EMAIL PROTECTED]   http://www.pcisys.net/~kscott

                This is the day that the Lord has made;
                Let us rejoice and be glad in it          -- Psalm 118:24

Reply via email to