When working on any non-trivial script, debugging is absolutely necessary. Currently, Window.alert() is the only usable method of debugging. $.writeln() also exist, but I don't even know where to look for that.
Dmitry Shpika commented
@Sergey Osokin It is deprecated and doesn't work on my version of OS X.
[Deleted User] commented
There is an Adobe ExtendScript Toolkit for this. Available in the Creative Cloud Desktop app list if you turn on Preferences > Apps > Show Older Apps