I have some apps that keep popping up ad windows. I want to find a way to automatically close certain app windows as soon as they appear. On Windows, I normally make a simple app in AutoIt and run it. What are my options on OS X?

  • 1
    Can you be a bit more specific? Which applications are involved here? – nohillside May 27 '13 at 12:57

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 && sleep 30 && pkill -x EasyConnect && osascript -e 'tell application "Safari" to close (tabs of windows where URL is "http://www.elisa.net/slmobi/")' & 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.


You could take a look up AutoIt alternatives on Stack Overflow.

If you're not bound to an App per se, you might also wanna take a look at Apple Script and take away a built-in language you might actually use even in an other Context.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .