2

Is there a way to bring the Linux terminal to the front of your screen from a python script? Possibly using some kind of os. command

I.e - Your python script opens up a GUI that fills the screen, but if a certain event happens that you want to see printed in the terminal to be viewed, but don't want to / can't show this information on the GUI (so please don't suggest that)

And if possible, hide it back behind your other windows again, if needed.

(Python 2, by the way)

Any suggestions greatly appreciated.

Aphire
  • 1,621
  • 25
  • 55
  • have you tried, `subprocess.Popen(somescript, shell=True)` or `subprocess.call(somescript, shell=True)` or `os.system("command")` – marmeladze Apr 29 '15 at 16:00
  • 2
    http://superuser.com/questions/142945/bash-command-to-focus-a-specific-window may help you. – m0dem Apr 29 '15 at 16:01
  • 1
    @marmeladze, I just tried both, os.system didn't have any effect, subprocess did bring terminal to the front, but only with an exception, I think that was probably down to my use of it, rather than it as a tool, so I will continue to try this method (exception is that the object is not iterable?), thanks for the point in the right direction though. – Aphire Apr 29 '15 at 16:16
  • @M0dem, the link only just came up, originally the comment just said "[may] help you" and I didn't understand, I will check that link now, cheers. – Aphire Apr 29 '15 at 16:18
  • @M0dem, after following that up, I have it working, thanks, if you want to post that as an answer, i'd be happy to accept. – Aphire Apr 29 '15 at 16:31

2 Answers2

1

Not in any generally supported way.

Some terminal applications may support the following control sequences. However, these sequences are not standardized, and most terminals do not implement them.

\e[5t  - move window to front
\e[6t  - move window to back

\e[2t  - minimize ("iconify") window
\e[1t  - un-minimize window

— from http://rtfm.etla.org/xterm/ctlseq.html

0

That "bring the Linux terminal to the front of your screen" is likely talking about terminal emulators running in an X Window environment. Ultimately this is accomplished by making a request to the window manager. There is more than one way to do this.

Community
  • 1
  • 1
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • I used the wmctrl to solve the problem in the end as M0dem suggested in comments, but as he did not post as an answer, I shall mark this up as the correct answer, because it gives more detail, and contains the solution I used. Cheers! – Aphire Apr 30 '15 at 07:31