I submitted another answer to the question regarding copying layers from one document to another in Photoshop. My solution proposes using a script to automate the process which I embedded in the answer. In fact, all my answers have been around automating the Creative Suite with scripts.
Unfortunately this doesn't have any syntax highlighting applied to it, which might make it easier for others to understand how it works and how they could apply it themselves. I suppose syntax highlighting isn't a major concern on this site, especially if not expecting code based questions and answers, but in this case it would be nice to have.