Thanks for the suggestion, neeks.

An even more elegant solution is to capture the frontmost app first, then hide the desktop, restart the finder, and then reactivate the app that was frontmost.

I’ve updated the script to reflect that. Works great with FastScripts, too.