Script for "Expand 1 (or x) Level"?

I posted this on another board, but there must be a way to script this.

I want to modify the Expand All command, so that rather than expand every sub-folder, and sub-sub-folder, and sub-sub-sub-folder, and so on, it just expands to the first level down in the folder hierarchy (or, even better, to a specified number of levels). That is, it shows you every top-level sub-folder in the selected folder, but these remain closed.

Haven’t a clue how to go about it, but it must be dead easy to you whizzes.

The only solution coming to my mind is user interface scripting but I don’t know if it’s actually possible.