Everything outlives its usefulness some day, even categories in Agenda databases, but it is difficult to track down categories to which no items are assigned. True, the Advanced Statistics in the category properties box will tell you how many items are assigned to a category, but for a large database, you would have to display and examine this box for every category.

The "Anyitems" macro is designed to detect "empty" categories and record their names in the note attached to a specially created category. You can then read the category note, or print it and then discard the empty categories which are no longer needed. The macro is long and looks mysterious, but what is does is very simple:

  1. Checks to make sure you are in the category manager
  2. Creates a new category called AnyItems, after checking whether it already exists.
  3. Creates a new view called AnyItems, after checking that it already exists
  4. Goes to the bottom of the categories and starts moving up one category at a time until it reaches the top category main (this is what the test for Depth = 0 does)
  5. If the category is a date, numerical or unindexed category, skip to the next category
  6. Create a view with items from the category, mark all the items in the view and then test for how many there are using the Markedinview variable
  7. If there are no items, go to the special AnyItems category and record this fact in the category note
  8. Once you reach the Main category, stop and display the note for the AnyItems category.

That's all really - there is a little more error checking so that the macro is less likely to go berserk, but in essence it just builds a view for each category, counts the number of items in the view and records this fact in a convenient category note.

There are a few settings in the macro which you can alter to suit your needs. The macro creates and uses a view which hides "inherited" items, so that a parent category will be recorded as empty if no items have been assigned to it directly, even though its children have assignements. You can change this in the macro by changing "Y" to "N" in line 44. You could also, if you wished, have the macro examine date and numeric categories by turning off the test for the type of category.

I hope this is useful
Stephen Yeo
24 January 1992