Applescript to bring a Terminal window to front

I have a shell script which runs a long-running processes in a Terminal window. I leave it running and work on other Terminal windows. I'd like to be notified when the shell script finishes, by bringing its window to front. I have following code, which I wanted to run at the end of the shell script: tell application "System Events" tell process "Terminal" try set win to (!code to get current window!) perform action "AXRaise" of win end try end tell end tell but I don't know how to get current window.

Applescript to bring a Terminal window to front

I have a shell script which runs a long-running processes in a Terminal window.

I leave it running and work on other Terminal windows.

I'd like to be notified when the shell script finishes, by bringing its window to front.

I have following code, which I wanted to run at the end of the shell script:

tell application "System Events"
    tell process "Terminal"
        try
            set win to (!code to get current window!)
            perform action "AXRaise" of win
        end try
    end tell
  end tell

but I don't know how to get current window.