Question
· 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.

Discussion (6)2
Log in or sign up to continue

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:

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-se...
https://stackoverflow.com/questions/11512373/findwindow-and-setforegroun...

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

https://www.autoitscript.com/forum/topic/113390-bring-application-or-pro...
https://www.programcreek.com/python/example/89828/win32gui.SetForeground...
https://metacpan.org/pod/Win32::GuiTest

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.