The obvious problem with such a solution is that it has to rely on a few uncertain things, like the position of a window, the availability of a menu item etc. PreFab Player is a commercial package that makes use of this method. It consists of an osax and a system extension. Among the most noteable features are that it lets you record scripts, and that it even supports mouse dragging. You can download a demo version from all major osax archives on the net.
More sophisticated solutions add real scripting to the application through a plugin or an extension.
A second possibility to circumvent the positioning problem is to use the move command instead. The following recursive subroutine will take any list as parameter and return it sorted in ascending order. This sorting routine works on strings as well as on numbers. The alternative is to use a loop, which is much slower. Note that there is a call to the handler within the handler itself.