This is based on an old example from Ray Camden, but is now 100% in script.  Feel free to use it.