Script menu crashes Entourage 2004 after category deletion

C

Conrad

If I delete a category in Entourage 2004 from an applescript run in Script
Editor, everything works fine. If I run the same script from the Entourage
Script Menu it crashes Entourage. What I believe is the relevant code
snippit is this:

repeat with delCategory in toDelete
delete delCategory
end repeat

set allCategories to categories

It seems to be crashing at either the delete statement, or at the retrieve
all categories statement.

I tried surrounding the delete statement with a couple of two second delays
in case the delete hadn't completed when I was getting the updated list, but
that made no difference.

Does anyone have any suggestions?

Best,
Conrad
 
C

Conrad

repeat with delCategory in toDelete
delete delCategory
end repeat

set allCategories to categories

After wrapping every line in a display dialog call, I can confirm that the
crash is actually on the line that calls for all the categories. Is there a
reason I should be able to get all the categories again from Script Editor
but not from Entourage's Script Menu?

Best,
Conrad
 
P

Paul Berkowitz

After wrapping every line in a display dialog call, I can confirm that the
crash is actually on the line that calls for all the categories. Is there a
reason I should be able to get all the categories again from Script Editor
but not from Entourage's Script Menu?

Is the Categories window open as you try to run his script? If so, close it
first. It won't update when it's open, and leads to errors, including
crashes.

Categories are a bit unusual in that they've been designed to show results
in alphabetical order by name, for some reason, rather than in order of
creation (by ID). Even though they have unique IDs they behave more like
objects that have only indices (like group entries). So every time you get
the full list, they have to re-sort first. I suspect that somewhere there's
a bug when they're still in memory from before the deletions.

If the crash persists even when the Categories window is closed, you've got
problems. I can't think of any workaround to refresh the categories or
memory, if this still doesn't work with Categories window closed. You could
keep a running tally (or do it all at once) to remove the toDelete items
from an original list of allCategories you get at the beginning of the
script before doing any deleting. (That you'd have to do in a repeat loop.
populating an empty list with every member of the original list that isn't
in the toDelete list. Do this before doing the deletions so you don't error
on non-existent objects.) Then you'd have the list of still existing
categories.

By the way, in Entourage 2004 you ought to be able to delete the whole
toDelete list at once, without having to run it in a repeat loop one by one.
In fact, I think even in earlier versions that should work with 'delete'. I
believe, although not with other commands.



--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
C

Conrad

The categories window was not open, but I did as you suggested, modifying a
preexisting allCategories list (before deleting the actual categories), and
that keeps it form crashing. Also, thanks for the pointer about delete. I
just pass it a list in my script now.
I just wish I didn't have to traverse the list over and over. Makes the
script pretty darn slow.
 
P

Paul Berkowitz

The categories window was not open, but I did as you suggested, modifying a
preexisting allCategories list (before deleting the actual categories), and
that keeps it form crashing. Also, thanks for the pointer about delete. I
just pass it a list in my script now.
I just wish I didn't have to traverse the list over and over. Makes the
script pretty darn slow.

That might be because you're passing it application objects. It might be
faster if you passed it ID numbers instead and then restituted the
categories from their IDs at the end. Also, if you have a really long list
you'll find speed improvements if you use 'my' when iterating a list:

set remainingCategories to {}
repeat with i from 1 to (count allCategories)
set theItem to item i of my allCategories

If this is running in a handler (subroutine) you either need to make the
list a global variable to use 'my' or use a similarly effective method
employing a script object, which I can explain.

Never concatenate lists to add a single item. That's terribly slow, Always
do it this way:

if {theItem} is not in toDeleteList then set end of remainingCategories
to theItem


It's _just_ possible that the combination of your using the other sort of
repeat loop (repeat with theItem in theList) in combination with Entourage's
re-sorting of categories helped create the problem. Although it should not
be necessary, using a

repeat with i from (count allCategories) to 1 by -1

backwards might help in the original script.

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
Top