Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close a floating window using AppleScript

One of my application processes occasionally creates a floating window that I'd like to programmatically auto-close.

I have no problem checking for the existence of this window through its name, but then I am unable to close it with neither close window "windowname" nor tell window "windowname" to close. E.g.

tell application "System Events" to tell process "processname"
    if exists window "windowname" then
        close window "windowname"
    end if
end tell

These result in:

error "System Events got an error: window "windowname" of process "processname" doesn’t understand the “close” message."

How can I close this window then?

like image 226
GJ. Avatar asked Oct 20 '14 13:10

GJ.


1 Answers

I can close a Finder window like this. Maybe you can do the same.

tell application "System Events"
    tell process "Finder"
        click button 1 of window 1
    end tell
end tell
like image 72
regulus6633 Avatar answered Jan 01 '23 21:01

regulus6633