1

So I have a python3 command-line tool that I use for some stuff, but I can't always pay attention to it, so I set it up to print('\a') when it wants to get my attention. This is nice, when I'm doing something else, but if I happen to be looking at the terminal it's running in, it's really annoying.

Is there a platform-independent way for a python3 script to tell if the terminal it's running in is in focus? Thanks in advance!

Joshua Snider
  • 705
  • 1
  • 8
  • 34
  • This is going to help you: https://stackoverflow.com/questions/10266281/obtain-active-window-using-python – Marc Sances Aug 13 '21 at 23:02
  • Wow, yes, that, but prettier is what I want. – Joshua Snider Aug 13 '21 at 23:16
  • Actually, that answer wasn't right, since I'm running in a wsl terminal and wnck doesn't work for that. – Joshua Snider Aug 16 '21 at 08:45
  • 1
    Unfortunately, I don't think there will be a way to detect WSL terminal focus. In such environment, Python is unaware of Windows, or any desktop enviroment at all. It thinks it is running in plain text terminal. – Marc Sances Aug 17 '21 at 08:42
  • Yeah, it's probably difficult to do, but I can just leave the TODO open for weeks until I stumble upon the answer. – Joshua Snider Aug 18 '21 at 02:50
  • I ended up solving my problem by just rewriting the code so that it only beeps when it's urgent and puts the rest in logs and printouts. – Joshua Snider Aug 21 '21 at 10:55

0 Answers0