This old thread is related:
but you still should look forward Peter’s code. I’ve always found a lot to learn by looking into his scripts.