2

I was just reading »How to revert to GNOME Classic?«. Some answers say that you should press Alt+Win to get the Add to panel dialogue. However my keyboard has no Win. So I was asking myself how to start the Add to panel window. Usually the best way is to enter the program name into a terminal. In this case I can't figure out the name.

I tested it on another computer and couldn't find the name in the process list. Also xwininfo or similar programs shoed no name. So what is the best way to figure out the name of the program which opened a (X) window.

2 Answers 2

9

Running xprop _NET_WM_PID from a terminal will put X into a special mode where you can click on a window to get that window's PID in the terminal.

Then run ls -l /proc/<pid>/exe and look at where the link is to to figure out what the program's file name is.

The following is a little python script take from a program I'm working on:

#! /usr/bin/env python

import os, subprocess

# Function based on code from apport
def get_window_pid():
    xprop = subprocess.Popen(['xprop', '_NET_WM_PID'],
            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    (out, err) = xprop.communicate()
    if xprop.returncode == 0:
        try:
            return int(out.split()[-1])
        except ValueError:
            return -1
    else:
        return -1

def get_window_exe():
    pid = get_window_pid()
    
    if pid == -1:
        return ''
        
    return os.path.realpath('/proc/' + str(pid) + '/exe')

if __name__=='__main__':
    exe = get_window_exe()
    if exe == '':
        print 'Unable to identify window\'s executable' 
    else:
        print exe

Save this into a file and run by typing python <filename>.py. Click on the window and it will print the program's name.

1
  • 1
    Following your answer, I created a bash script with: ls -l "/proc/$(xprop _NET_WM_PID | sed "s/^.*= //")/exe"
    – Anderson
    Oct 20, 2022 at 14:47
1

Based on iBelieve's answer:

alias fxname='basename $(ll /proc/$(xprop _NET_WM_PID | awk "{print \$NF}")/exe | awk "{print \$NF}")'

The $NF in the awk commands must be escaped so it's not interpreted as a shell variable. As soon as you run it a reticle will appear for you to click on the desired window.

1
  • 1
    ll needs to be ls -l. Not everyone has an ll alias. Jan 16, 2023 at 2:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .