LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-18-2020, 10:32 AM   #1
blueray
Member
 
Registered: Feb 2020
Location: Bangladesh
Distribution: Debian, Ubuntu, Linux Mint
Posts: 136

Rep: Reputation: 2
close all except selected window


I want to close all instance of nemo file browser except the selected window.

I have to following script to do that.

Code:
#!/bin/bash

not_to_close=$(xdotool selectwindow)
class_name=$(xprop WM_CLASS | cut -d '"' -f2)

for i in $(xdotool search --desktop 0 --class "$class_name"); do
    if [ "$not_to_close" != "$i" ]; then
        xdotool windowclose "$i"
    fi
done
However, it has a small issue. I have to click twice (once for xdotool once for xprop), which I do not want to do.

How can I reduce the click to one?

P.S. I know I can hardcode the class name using --class "nemo", but it has other issues in addition to not being generic.

Last edited by blueray; 12-18-2020 at 11:06 AM.
 
Old 12-18-2020, 11:25 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
do you mean something like this?
Code:
xprop -id $not_to_close WM_CLASS
 
1 members found this post helpful.
Old 12-18-2020, 11:40 AM   #3
blueray
Member
 
Registered: Feb 2020
Location: Bangladesh
Distribution: Debian, Ubuntu, Linux Mint
Posts: 136

Original Poster
Rep: Reputation: 2
Thank you very much.

My end result looks like:

Code:
#!/bin/bash

not_to_close=$(xdotool selectwindow)
selected_window_class_name=$(xprop -id $not_to_close WM_CLASS | cut -d '"' -f2)

for i in $(xdotool search --desktop 0 --class "$selected_window_class_name"); do
    if [ "$not_to_close" != "$i" ]; then
        xdotool windowclose "$i"
    fi
done
 
  


Reply

Tags
bash, linux, xwindow



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] A way to close all windows except the one that has the focus in the Seamonkey browse. stf92 Slackware 12 09-13-2013 05:20 AM
I need a script to Delete Selected BackupFiles and Restore selected backup file finalwar Linux - Newbie 3 07-20-2010 02:10 AM
Granting selected user access to selected network interface dexen Linux - Networking 2 10-04-2009 03:51 AM
Close all window in a window manager zghh Linux - Software 1 12-20-2006 03:18 PM
Close ssh for all except one IP krilen Linux - Security 13 03-26-2004 05:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration