Eduard Lebedyuk · Mar 6, 2020

Force terminal to the foreground after current command finishes running

Simple problem:

  1. I leave a long-running command in terminal
  2. Switch to another task(s)
  3. Remember that I need to check on my command after a few hours

Is there any way to force terminal to the foreground after current command ends?

This is Windows with cterm/iristerm although Putty/Kitty solution would also be nice.

0 335
Discussion (6)3
Log in or sign up to continue

Putty has options to take certain actions when it receives a BELL character (  $c(7)  ). Can you change your routine to return a BELL when it completes?

Thank you, Marc!

With Kitty there's even a Put Window on Foreground option:

I've tested with

h 10 w $c(7) 

and it works!

Is there anything similar for cterm/iristerm?

$c(7) also works in MacOs -- makes terminal window jump

Up. Still searching for Windows/CTerm solution.

Cache Terminal doesn't have a setting similar to Putty.

Windows has methods for finding a specific window that belongs to another app and bringing it to the foreground. You could write a C++ or C# program to do that:

Or many scripting languages have libraries that use those Windows methods:

It's not a pretty solution but you can achieve it using a terminal script (iristerm/cterm). The script will call your routine and when it ends it will throw a popup alert informing that your routine did finish. It will not bring the terminal to the foregroung but you get the alert.

Save this to a file:

send: d ^myRoutine<cr>
wait for: USER>
execute: mshta vbscript:Execute("msgbox ""Routine myRoutine finished processing."",48:close")

In terminal, press ALT+S and select the your script file and when the routine ends you will see a popup.