1

I'm trying to make an apple script to allow me to manage a cpp project automatically. And I used Jenkins too.

Basically, the cpp project is a kind of infinite loop, which will execute in a terminal. And I set Jenkins rebuild and execute it per 20 sec. In other words, my pc should do the tasks below:
1) rebuild the project;
2) execute the project;
3) wait for 20 sec;
4) close the terminal.

However, when I arrive at 4), a dialog will pop up: Do you want to close this window?
So I have to click the button "Close".

My question is: how to code in applescript to do the 4) automatically?

Here is my applescript:

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
Yves
  • 11,597
  • 17
  • 83
  • 180

2 Answers2

2

However, when I arrive at 4), a dialog will pop up: Do you want to close this window? So I have to click the button "Close".

But you can do that using AppleScript too (via GUI scripting thru System Events), so nothing you've said is a problem so far.

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
matt
  • 515,959
  • 87
  • 875
  • 1,141
0

I wonder if this might help: Running process in background after closing terminal

The problem might be that what you're lastly running in the terminal is a process (matrix.out) that will get killed by closing the window, and you don't want that, right? So it may be that you need to alter the matrix.out script using the technique described (if possible) to keep it from doing that.

It may also be possible to solve your problem by making matrix.out executable (chmod it to executable or use Kilometre) and just "open it" using vanilla applescript.

Community
  • 1
  • 1
CRGreen
  • 3,406
  • 1
  • 14
  • 24