Macos 用于关闭OSX中每个未使用终端窗口的Applescript或Shell脚本

Macos 用于关闭OSX中每个未使用终端窗口的Applescript或Shell脚本,macos,shell,applescript,Macos,Shell,Applescript,我有一个在OSX的UI用户会话中运行的应用程序(一个在终端窗口中运行的mono应用程序,一个命令行程序)。有时,无论出于何种原因,此mono应用程序都会退出,并且每2分钟启动一次的shell脚本会检查ps ax | grep“mono”是否只返回grep命令作为唯一的mono进程。如果是这样,生成一个新的终端窗口,并在该终端窗口中再次运行mono程序 无论如何,有时这会导致大量终端窗口打开。我想要的是附加到这个shell脚本中,或者在Applescript中,我可以在我的mono应用程序中调用它

我有一个在OSX的UI用户会话中运行的应用程序(一个在终端窗口中运行的mono应用程序,一个命令行程序)。有时,无论出于何种原因,此mono应用程序都会退出,并且每2分钟启动一次的shell脚本会检查
ps ax | grep“mono”
是否只返回grep命令作为唯一的mono进程。如果是这样,生成一个新的终端窗口,并在该终端窗口中再次运行mono程序

无论如何,有时这会导致大量终端窗口打开。我想要的是附加到这个shell脚本中,或者在Applescript中,我可以在我的mono应用程序中调用它来关闭每个没有运行mono进程的终端窗口。Applescript能否确定终端窗口是否正在运行某个程序?壳牌公司能确定吗?如果是,怎么做?

我看了这篇文章:

如果进程不忙,那么它显然目前没有运行某些东西,这是我对此的看法

问题是,如果你的mono进程在前台运行,终端正忙,那么我猜你运行的脚本将被搁置。您可以做的是提取终端窗口的输出(文本),并在那里查找mono进程。(我真的认为,关闭所有不忙的窗口是最好的。比如说,如果你有一个工作窗口,那么你可以为该窗口指定一个“特殊标题”,因此,使用if测试来避免它被关闭。(它可能大部分时间都不忙。)

这怎么样

将processCheckName更改为您的进程

set processCheckName to "du"
tell application "Terminal"
    --activate
    set theWindows to every window of it
    repeat with thisWindows in theWindows
        set biglist to {}
        set theTabs to every tab of thisWindows
        repeat with i from 1 to number of items in theTabs
            set this_item to item i of theTabs
            set theProc to processes of this_item
            if theProc contains processCheckName then
                copy id of thisWindows to end of biglist
            end if
        end repeat
        if (id of thisWindows) is not in biglist then

            close thisWindows
        end if
    end repeat
end tell

很好。但是你可以用
close aWn
替换系统事件调用。我已经尝试过了,关闭窗口和所选窗口,我在测试时发现了一个错误,在测试选项卡的业务时出现了一个错误。如果没有,应该是
(忙于aTab)然后
非常感谢Mark,你完全正确,现在我在每个选项卡中执行了一个脚本,它也删除了它的ui脚本:
set processCheckName to "du"
tell application "Terminal"
    --activate
    set theWindows to every window of it
    repeat with thisWindows in theWindows
        set biglist to {}
        set theTabs to every tab of thisWindows
        repeat with i from 1 to number of items in theTabs
            set this_item to item i of theTabs
            set theProc to processes of this_item
            if theProc contains processCheckName then
                copy id of thisWindows to end of biglist
            end if
        end repeat
        if (id of thisWindows) is not in biglist then

            close thisWindows
        end if
    end repeat
end tell