Tuesday, April 30, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 3289  / 1 Year ago, sat, november 19, 2022, 9:29:41

I need to simulate the behavior of the keyboard shortcut (ALT+F4) using Terminal for a given application.



If I open for example gedit and click ALT + F4 , then GEDIT will be xkilled.
If I want to achieve same thing using Terminal, how should I proceed?



The following command (in order to kill gedit process) works fine:



kill $eval `pidof gedit`


yet, the command



xkill -id gedit


prompts me to click on the application client window in order to xkill it, thing That I want to avoid from the beginning.



The reason why I want to achieve this behavior is that some applications clients keep their process running, even though you ALT+F4 it.
My need is that I have an application that starts up on every login and I need to automatically close its client 3 or 5 seconds after it shows up.


More From » xorg

 Answers
1

An equivalent of xkill is the windowkill function in xdotool. If you don't have xdotool installed, please run



sudo apt-get install xdotool


With this tool you can indeed kill a window by using the search option and by specifying its class:



xdotool search --class gedit windowkill


You can find the pid of the process with getwindowpid, but just specifying the name of the class of window (i.e --class gedit) is enough. The tool is non-interactive in the sense that you do not need to click on a window to kill it as you sometimes need to do with xkill.



More information on the options available with xdotool are available with man xdotool and at the Ubuntu manpages online. The manpages explain well how xdotool can be incorporated into a script much easier than xkill could be.



So I think probably xdotool's windowkill option is what you want and it may be more handy than that of xkill.



However, if you still want to use xkill and feed it the window's resource id, so that it closes the window without prompting you, you could parse the output of xwininfo, as in this example using the program Meld:



xkill -id $(xwininfo -name Meld | awk -F ':*"*' '{print $3}')


However, the name of the program sent to xwininfo must be in the proper case, so launch the program beforehand, and, in our example here, see if it is Meld or meld.



I prefer the xdotool command I gave above, as the case doesn't have to be correct: Meld or meld will work as the search --name switch instead uses regex to match a given string and ignores the case.


[#34346] Sunday, November 20, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
fectlyole

Total Points: 64
Total Questions: 110
Total Answers: 110

Location: Nicaragua
Member since Thu, Feb 3, 2022
2 Years ago
fectlyole questions
Sun, May 8, 22, 02:54, 2 Years ago
Mon, Jun 21, 21, 16:56, 3 Years ago
Fri, Jul 9, 21, 17:44, 3 Years ago
;