As the "quick and dirty way", I would probably just call a shell script. You just would execute the command "osascript". You can make osascript tell the application or even the Finder to close or move windows.
I think that "quick and dirty way" is ok for this case. But I have problems with osascript. I use command:
osascript -e 'tell application "FooApp" set bounds of window 1 to {100, 100, 500, 500}'
I get error "execution error: FooApp got an error: Can't set bounds of window 1 to {100, 100, 500, 500}. (-10006).
Interesting that this command work fine for TextEdit
osascript -e 'tell application "TextEdit" set bounds of window 1 to {100, 100, 500, 500}'
What do I need to do make my application compatible with osascript?