Title: First Script, request for critiques (long message, sorry)
Hello,
I have gotten my first AppleScript into a form that is somewhat recognizable, and I am ready for some feedback from people who know what is going on. I have a few questions and concerns about the script, primarily with its performance.
First, the script does do exactly what I want. I select a folder, invoke the script, and the messages in the folder are moved into subfolders based on the month and year that the message was sent. The bad news is that I tried the script on a folder with just over 6000 messages in it, and it took about two hours to complete. This seems very slow to me. Any suggestions to make the script faster would be great.
Two, is there any way to move messages as a list, rather than one-by-one in a repeat loop?
Three, any suggestions on how to only grab the subfolders of the selected folder one time and search that for the new archive folder would be great. Right now, I loop all the subfolders every month that is being considered for archiving. Still, this is magnitudes faster than the actual selection and moving of messages.
Thanks to all those who have helped me already, and thanks in advance to anyone willing to look through this and help me to learn AppleScripting a little better.
Ken Scott
Here is my script:
(*********************************************************************
** Script: Archive to Dated Subfolders
** For application: Microsoft Entourage
** Author: Kenneth Scott
** Date: June 25, 2001
** Version: 1.0
**********************************************************************
**
*********************************************************************)
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 1994 -- 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
--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
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 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
--
<>< 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
