Detaching or attaching a Mac to an external display can sometimes leave windows placed partially or wholly offscreen. This script can be used to bring them back to the main desktop (a similar thing can be done using the "Gather Windows" button of the Displays preference panel, but this script can be invoked from a keyboard shortcut, if you need to do this regularly).
Use responsibly.