如何使用AppleScript关闭浮动窗口

时间:2014-10-20 13:15:27

标签: macos applescript

我的一个应用程序进程偶尔会创建一个浮动窗口,我想以编程方式自动关闭。

我通过其名称检查此窗口是否存在没有问题,但是我无法使用close window "windowname"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

这导致:

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

如何关闭此窗口呢?

1 个答案:

答案 0 :(得分:0)

我可以关闭这样的Finder窗口。也许你也可以这样做。

tell application "System Events"
    tell process "Finder"
        click button 1 of window 1
    end tell
end tell