You can register for the BAG_UPDATE and check if there are any "locked" items in bags, and if not then do another consolidate pass.
Another method is to create an OnUpdate that turns on at a BAG_UPDATE event and counts out a second before running a consolidate pass (then hides itself so it doesn't run until next BAG_UPDATE).
It's worth mentioning that BAG_UPDATE can happen
a lot. Literally hundreds of times when you log in or zone. So you'll want to make sure it doesn't do anything lengthy in response to every BAG_UPDATE.
edit: This mod:
http://www.wowinterface.com/download...php?s=&id=4118 has some of what you're looking for. Look for the words 'Consolidate' in its lua and 'WaterboyBagUpdateFrame' in its xml. You're welcome to take parts of it and use as your own or do whatever you want with it. It does the second OnUpdate approach above. Your mod sounds really useful good luck with it