Auto close windows that pop up?
You could save a script like this as a stay open application in AppleScript Editor:

on idle
    tell application "TextEdit" to close windows where name contains "Untitled"
    return 1
end idle


You can open it at login by adding it to login items. return 1 waits one second before running the idle handler again. killall applet terminates the process.

Closing windows with System Events:

tell application "System Events" to tell process "Preview"
    repeat with w in (get windows where title contains "pdf")
        click (button 1 of w where description is "close button")
    end repeat
end tell


I use this function to connect to a 3G network:

mlk() { pkill -x EasyConnect; open -ga Mobiililaajakaista &amp;&amp; sleep 30 &amp;&amp; pkill -x EasyConnect &amp;&amp; osascript -e 'tell application "Safari" to close (tabs of windows where URL is "http://www.elisa.net/slmobi/")' &amp; disown $!; }

open -g opens the application on the background. Without disown the shell shows a message like [1]+  Done after the background job finishes. pkill -x is like killall but it doesn't show an error message if it doesn't match any processes.