Applescript 如何循环所有终端窗口,停止任何正在运行的进程,并在窗口未命名为特定字符串时关闭窗口?

Applescript 如何循环所有终端窗口,停止任何正在运行的进程,并在窗口未命名为特定字符串时关闭窗口?,applescript,Applescript,我有一个名为“myTerminalWindow”的终端窗口,无法关闭所有其他未命名为“myTerminalWindow”的终端窗口。其他窗口可能正在运行进程,因此我们必须在关闭窗口之前停止进程。我如何做到这一点 无论关闭终端窗口的首选项是如何配置的,这里有一种方法都应该有效: tell application "Terminal" set theWindows to windows repeat with aWindow in theWindows if (nam

我有一个名为“myTerminalWindow”的终端窗口,无法关闭所有其他未命名为“myTerminalWindow”的终端窗口。其他窗口可能正在运行进程,因此我们必须在关闭窗口之前停止进程。我如何做到这一点

无论关闭终端窗口的首选项是如何配置的,这里有一种方法都应该有效:

tell application "Terminal"
    set theWindows to windows
    repeat with aWindow in theWindows
        if (name of aWindow) contains "myTerminalWindow" then
            display dialog ("Will not close " & name of aWindow)
        else
            set theProcesses to processes of aWindow
            set clean commands of current settings of aWindow to theProcesses
            close aWindow without saving
        end if
    end repeat
end tell
通过使用当前正在运行的进程列表更新“clean commands”属性,可以告诉终端可以在没有提示的情况下终止这些进程

如果您想要一种更复杂的结束正在运行的进程的方法,那么您可以遍历正在运行的进程列表,并以您认为合适的方式关闭它们。终端的“do script”命令对此很有用