如何使用 AppleScript 关闭浮动窗口

GJ.*_*GJ. 10 macos applescript

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

我没有问题,检查此窗口,通过它的名字的存在,但当时我无法既不关闭它close window "windowname"也不是tell window "windowname" to close。例如

tell application "System Events" to tell process "processname"
    if exists window "windowname" then
        close window "windowname"
    end if
end tell
Run Code Online (Sandbox Code Playgroud)

这些导致:

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

那我怎样才能关闭这个窗口呢?

reg*_*633 2

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

tell application "System Events"
    tell process "Finder"
        click button 1 of window 1
    end tell
end tell
Run Code Online (Sandbox Code Playgroud)