Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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?

share|improve this question
1  
Can you be a bit more specific? Which applications are involved here? –  patrix May 27 '13 at 12:57

2 Answers 2

up vote 0 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.