对多个 shell 脚本使用一个终端实例?

Use one terminal instance for many do shell scripts?

所以,我需要制作一个 AppleScript 以通过 ssh 连接到我的 mint 无头服务器。我不需要传输文件,只需 运行 命令。问题是,当我使用一个 do shell 脚本进行 ssh 时,它与其他脚本处于不同的实例中。另外,如果我不必使用击键并将终端放在前面,那就更好了。

编辑:如果你们告诉我你们为什么反对这个 post。

会有所帮助

不确定这是否是您想要的,但使用 Terminal.app 您可以做到:

set shellScript to "echo" & space & quoted form of "Test Message"

 tell application "Terminal"
    activate
    try
        if (exists tab 1 of window 1) then
            do script with command shellScript in front window
        else
            do script with command shellScript
        end if
    on error
        beep
    end try
end tell

上面的代码在window前面执行shellScript,或者在没有window打开时在新的window中执行。希望对你有帮助。

加法
我认为没有 AppleScript 脚本命令到 hideapplication。 使用 System Events 我们可以做一个 keystroke,所以让我们做 cmd-h 隐藏一个应用程序:

tell application "System Events"
    tell application process "Terminal" to set frontmost to true
    -- delay 0.25 -- in case it does not work
    keystroke "h" using command down
end tell

我不知道 Terminal.app 如何隐藏和执行脚本,但您会发现的。

或者将 Terminal-Window 放入另一个 Finder Space.