Back when I started writing Scripts for Photoshop, I'd have loved having Boilerplate code to borrow and learn from. I've put a repository on GitHub with my take on that - still in early, alpha stage but some CoffeeScript stuff is there, ready to be forked: feel free to contribute!
BridgeTalk, the system that enables messaging between applications in the Adobe scripting ecosystem, is prone to failure when evaluating functions via .toSource() - be aware and stringify them in advance!
In a ScriptUI Window different components are usually registered for Events, and fire their own Handlers. You can build some interconnection, so for instance a Button's 'click' handler triggers a change in a ListBox, which in turn reacts to its own 'onChange' Event. It's quite easy to decouple this interaction, provided that you set up your code properly.
It's not uncommon, when scripting for Adobe applications, to borrow JS libraries that have been originally written for web development. While the new generation of Adobe HTML Extensions will run on the Chromium Embedded Framework, traditional ExtendScript code is based upon a different, older engine. Besides ECMAScript unsupported features (i.e. ES 5) I've noticed that using minified JS code is a risky business - scripts can break or fail silently. I've set up a proper testing environment to inspect them.
In your code you may need to run a ScriptUI component's callback, or simulate a user interaction, maybe as a part of a subroutine. There are few ways to do this, with slight differences in the behavior: directly, using call(), notify() or dispatchEvent() - I've set up a commented demo Dialog that shows them all.
If you aren't in love with Adobe's ExtendScript Toolkit, welcome to the club. I've come up with a Sublime Text 2 build system package that lets you run JSX scripts directly from Sublime Text targeting Photoshop, Command+B or CTRL+B and voilà!
In order to build a script that requires user input (from a GUI) and can be recorded into an Action, you must code a particular set of features - I'll be providing a commented example, to be used as a template.
ScriptUI Windows can be tricky in Photoshop, especially if you want to create a non-modal, persistent and idle palette. While a couple of workarounds are possible, as I've shown in a previous post, there's a better alternative involving BridgeTalk.