Thanks for the distraction Tobias (@Nr.5-need_input )
You can find the above-mentioned AppleScript code here.
A while back I wrote something similar for a private project and then some years later discovered this which happens to be freely available. I've used its recursive behaviour in modified form for a number of KM projects because it runs a lot quicker than the code I produced originally!
I leave it as an exercise for the reader to understand how it works/can be modified