The time that my boss promised that we could write an AppleScript for InDesign which would allow adding an index to an InDesign document --- turns out it was 4 levels deep, and when I asked about doing this on the InDesign mailing list, Olav Martin Kvern who was then Adobe's Scripting Evangelist declared that it was impossible, because only the first level had support.
After a bit of experimentation I determined that it was necessary to verify the existence of a given index entry at a given level, and that if it existed, one could add additional entries --- if it didn't exist, then it was necessary to create the level above as an index entry, and then it was possible to add the new one.
I probably have the code somewhere, but haven't done any Applescripting for a while now (kind of miss it, Powershell is nowhere as comfortable, and there doesn't exist an equivalent to Application Dictionaries).