Python Forum
Current foreground application
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Current foreground application
#1
Trying to figure out the name of the current foreground application running, in Linux. Having things like the PID and Windowtitle are nice ... But, I need the application name itself. Like Chrome, nano, vim, etc ... If anyone knows how to do it in a bash script that'd be great also. But, I'll gladly take a python script.
Reply
#2
I'm not sure what you're looking for by "the" foreground application. I might have multiple foreground applications running in multiple windows. There's no easy way in Linux to distinguish between them.

The psutil package has methods for going from PID to process name, and finding process parents/children, but I'm not sure which PID you are interested in.
Reply
#3
I mean, whatever application has focus. Like now, I'm in Chrome making this reply. So, Chrome is focused and is in the foreground.

I'll check out library you mentioned.
Reply
#4
That will depend on the window manager and whether you can poll it and get an answer. I don't know an easy way to do that (either with or without python).
Reply
#5
Well, I'm using i3, with polybar ontop of it. I can use linux commands to get a list of windows. wmctrl -l ... In polybar, there's a module that gets the window title of the "active" window. It's written in c++ and I don't know c++.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Starting and running .bat in background, tkinter in foreground ProfMeowintgon 9 1,496 Sep-01-2023, 12:00 PM
Last Post: deanhystad
  How to send data from a python application to an external application aditya_rajiv 1 2,178 Jul-26-2021, 06:00 AM
Last Post: ndc85430
  A problem with a TButton's foreground 'active' color. Mik3e 0 1,408 Sep-10-2020, 01:12 AM
Last Post: Mik3e

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020