You can find a couple ideas on this post –
including some code (post #8/10) that I am currently using.