【问题标题】:applescript: how to terminate an executing terminalapplescript:如何终止正在执行的终端
【发布时间】:2016-05-08 16:39:45
【问题描述】:

我正在尝试制作一个苹果脚本来让我自动管理一个 cpp 项目。我也用过 Jenkins。

基本上,cpp 项目是一种无限循环,它将在终端中执行。我设置 Jenkins 重建并每 20 秒执行一次。换句话说,我的电脑应该完成以下任务:
1) 重建项目;
2) 执行项目;
3) 等待 20 秒;
4) 关闭终端。

但是,当我到达 4) 时,会弹出一个对话框:您要关闭此窗口吗?
所以我必须点击“关闭”按钮。

我的问题是:如何在 applescript 中编写代码以自动执行 4)?

这是我的小程序:

tell application "Terminal"
    do script "cd /Users/Shared/Jenkins/Home/workspace/test"
    do script "make clean" in window 1
    do script "make" in window 1
    do script "./matrix.out" in window 1
    delay 20
    close window 1  # problem's here
end tell

【问题讨论】:

    标签: macos terminal applescript


    【解决方案1】:

    但是,当我到达 4) 时,会弹出一个对话框:您要关闭此窗口吗?所以我必须点击“关闭”按钮。

    但您也可以使用 AppleScript(通过系统事件通过 GUI 脚本编写)这样做,所以到目前为止,您所说的都不是问题。

    tell application "Terminal" to activate
    tell application "System Events"
        tell application process "Terminal"
            tell its window 1
                tell its sheet 1
                    click button "Close"
                end tell
            end tell
        end tell
    end tell
    

    【讨论】:

      【解决方案2】:

      我想知道这是否有帮助: Running process in background after closing terminal

      问题可能是你最后在终端中运行的是一个进程(matrix.out),它会被关闭窗口杀死,你不希望这样,对吧?因此,您可能需要使用所描述的技术(如果可能)更改 matrix.out 脚本以防止它这样做。

      也可以通过使 matrix.out 可执行(将其更改为可执行或使用 Kilometre)并使用 vanilla applescript “打开”来解决您的问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多