Hello,The next example will speed by almost all of that time, if you have enough memory for it to work at all. (6000 messages is an awful lot for it to do a ‘wose’ filer on: it might just poop out instead. Better give Entourage 30+ MB memory before you try this. 50 would be good.
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.
You can do better than that. Entourage implements filters, otherwise known as ‘whose clauses’ for every single element of every class (except one, which is a bug). You’ve even used them in your script, but not taken full advantage of them: you can do more than set a list to the: you can act on them with an event (e.g. Move). You can’t do this after you’ve turned them into an AppleScript list, since lists in AppleScript don’t yet implement ‘whose’ clauses. (One of the AppleScript engineers says they will, eventually.). You have to do it at the moment:
Two, is there any way to move messages as a list, rather than one-by-one in a repeat loop?
move ((every message of theBaseFolder) whose ((time sent ? datestart) and (time sent ? dateend))) to ArchiveFolder
Boom! All move at once.
Every folder has its own unique ID number. Just store that.
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.
set ArchiveFolderID to ID of ArchiveFolder
At the very top of your script, you initialize a property:
property ArchiveFolderID : 0 -- or "", or anything
Later, you say:
if ArchiveFolderID = 0 then
-- get the Month, archiveFolderName, theBaseFolder, etc.
set ArchiveFolder to my getArchiveFolder(archiveFolderName, theBaseFolder)
else
set ArchiveFolder to folder id ArchiveFolderID
end if
Simple.
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.You’re doing pretty well.
or:
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))) -- skip *)
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 theMonthText to text –2 thru –1 of ("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
--
Paul Berkowitz
