Refocusing terminal after closing GUI window

I’m using a button on a MIDI controller through MIDIdef to close a GUI window. However when closing the window to terminal does not automatically refocus and you have to do this manually with a mouse. It’s for a piece for an exhibition so I want the only interaction to be through the MIDI controllers. Is there anyway to do this through Supercollider?

I’ve tried setting

w.alwaysOnTop_(false)

any suggestions?

I don’t quite understand what you mean by refocusing the terminal. Why do you need focus on a specific window if you’re interacting using MIDI controllers and what window needs to have focus?

When you say ‘terminal’, do you mean the terminal in the OS, or do you mean SCide?

If you post some more info about what computer and what OS etc. you are using it easier to help you. And if you can include a code example that would be even more helpful.

+Eirik

Sorry if I’m not being clear! So the first part of the interaction takes place by running some Python code in the OS terminal, which is then sending OSC to Supercollider. On receiving the message it will bring up a GUI window from Supercollider. Once the user has finished making sound through the GUI they will press a button on the MIDI controller to close the window. However when this happens, the OS terminal is then out of focus and needs to be clicked on by a mouse.

e.g.

			(
				OSCdef( \test4, {
					arg msg; 

if (msg != 0,
						{
							{
								Window.closeAll;
								w = Window.new("test", Rect.new(500.rand, yPos, wWidth, wHeight))
								.front // bring to front
								.alwaysOnTop_(true) // different syntax for w.alwaysOnTop = true;
								.background_(Color(78/255, 80/255, 85/255))
								.onClose_({
									Pdef(\pattern1).stop;
									Pdef(\pattern2).stop;
									Pdef(\pattern3).stop;
									Pdef(\pattern4).stop;
									a.free;
									b.free;
									c.free;
									d.free;
									~d2.free;
								});
}.defer;
}
);

});
)

Thanks in advance!

I dont’ what OS you running so I can only assume you are using macOS:
On macOS you could do:

var terminalApp = "iTerm2"; //or "Terminal" if that's your choice
"osascript -e 'tell application \"%\" to activate'".format(terminalApp).unixCmd;