User avatar
thagrol
Posts: 5570
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Get name of application with focus

Tue Sep 14, 2021 8:00 pm

My search skills have failed me...

Anyone have a example python code (or can point me in the right direction) that can find the file name of the desktop application whose window currently has focus?

Bonus points if:
  • No non standard modules, libraries, or external programs are needed.
  • It's nto specific to a single window manager
  • It's cross platform.
I'm a volunteer. Take me for granted or abuse my support and I will walk away

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

bls
Posts: 1689
Joined: Mon Oct 22, 2018 11:25 pm
Location: Seattle, WA

Re: Get name of application with focus

Tue Sep 14, 2021 9:26 pm

thagrol wrote:
Tue Sep 14, 2021 8:00 pm
My search skills have failed me...

Anyone have a example python code (or can point me in the right direction) that can find the file name of the desktop application whose window currently has focus?

Bonus points if:
  • No non standard modules, libraries, or external programs are needed.
  • It's nto specific to a single window manager
  • It's cross platform.
Doesn't meet your no external programs, but looks like xdotool could do this: https://unix.stackexchange.com/question ... e-in-gnome

Oops. You said application. :roll:
Pi tools:
Quickly and easily build customized-just-for-you SSDs/SD Cards: https://github.com/gitbls/sdm
Easily run and manage your network's DHCP/DNS servers on a Pi: https://github.com/gitbls/ndm
Easy and secure strongSwan VPN installer/manager: https://github.com/gitbls/pistrong
Lightweight Virtual VNC Config: https://github.com/gitbls/RPiVNCHowTo

User avatar
thagrol
Posts: 5570
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Get name of application with focus

Tue Sep 14, 2021 11:36 pm

Hmm. I'd prefer a python native solution but xdotool is in the repository so it might be possible to kludge something together with subprocess.
I'm a volunteer. Take me for granted or abuse my support and I will walk away

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
thagrol
Posts: 5570
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Get name of application with focus

Wed Sep 15, 2021 12:09 am

Looks like I can get close to what I'm after with info from that link. Thanks.

If anyone has another approach feel free to suggest it.
I'm a volunteer. Take me for granted or abuse my support and I will walk away

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

Return to “Python”