Close all windows script

Forum Forums General Tips and Tricks Close all windows script

  • This topic has 14 replies, 5 voices, and was last updated May 2-8:34 am by Lead Farmer.
Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #105448
    Member
    Lead Farmer

      This tiny scrip will gracefully close all windows.

      How to add the script

      Extract somewhere on your PC
      1) You can use the app Add Key, select and key binding and the address of the script you want to use.
      2) Add the shortcut manually adding the short in desktop settings, like in IceWM .example.
      key "Ctrl+Shift+k" /home/oren/Documents/close_all_windows.sh
      3) you can add a menu entry with Shortcut Maker or do it manually.

      Warning: may kill running programs.

      • This topic was modified 1 week ago by Lead Farmer.
      • This topic was modified 6 days, 18 hours ago by Lead Farmer.
      #105475
      Member
      RJP
        Helpful
        Up
        0
        ::

        Very good script, but there should be a warning that it kills running programs from desktop too.

        For Shortcut Maker you could set variable which is working all locales.

        #Desktop Shortcut
        FILE_WRITE_LOCATION="$(xdg-user-dir DESKTOP)"
        • This reply was modified 6 days, 18 hours ago by RJP.
        #105480
        Member
        Lead Farmer
          Helpful
          Up
          0
          ::

          Very good script, but there should be a warning that it kills running programs from desktop too.

          I guess it depend on the program, I run the script while downloading a file with Brave browser, and it didn’t close browser, it show a massage if I wan’t to exit, either way I add a warning.

          #105679
          Member
          antixcat
            Helpful
            Up
            0
            ::

            Thank you for this. I was looking for a way to do this specifically and this works great.

            #105710
            Member
            ile
              Helpful
              Up
              0
              ::

              Hello
              It closes tint2. (ft10-transformation)

              #105715
              Member
              Lead Farmer
                Helpful
                Up
                0
                ::

                Hello
                It closes tint2. (ft10-transformation)

                I’m guessing this is a bad thing, and you want to keep tint2?

                If that so, here the script with one window exception, that will not close.

                #!/bin/bash
                #
                # Close all windows 1.1 
                # With exception
                #
                
                WINDOWSID=$(wmctrl -l | awk '{print $1}')
                NUMWIN=$(wmctrl -l | wc -l)
                
                # exception 
                EXCP="tint2"
                EXCPID=$(wmctrl -l | grep -i "$EXCP" | tail -1 | awk '{print $1}')
                
                for ((i = 1 ; i <= $NUMWIN ; i++)); do
                  ID=$(echo "$WINDOWSID" | head -$i | tail +$i)
                  if [[ "$ID" != "$EXCPID" ]]; then
                    wmctrl -i -c $ID
                  fi
                done
                
                exit 0

                Make sure the name of exception (EXCP=”tint2″) is the name you want to exclude, you can check with:

                wmctrl -l

                • This reply was modified 2 days, 3 hours ago by Lead Farmer.
                #105731
                Member
                Robin
                  Helpful
                  Up
                  0
                  ::

                  Hello Lead Farmer,

                  great Idea, your script.

                  I’d propose another exception:
                  If aCSTV is set to a recording, it’s a really bad idea to close it by your script. This would ruin your current recording.

                  To avoid this, while still being able to close it with your script in non-recording mode, you’d simply need to check for its recording flag file, which is only present when a recording is running:

                  Search for “/dev/shm/aCSTV-$$05.tmp” wherein $$ stands for the arbitrary PID of the currently running aCSTV instance, which might have different number of digits depending on what the system has assigned.

                  e.g.
                  aCSTV-386286105.tmp

                  If this file is present, don’t close the window-ID of aCSTV and also not the window ID of MPV. Both are involved in recording. Besides of this, aCSTV shuts down properly and completely when applying the command found in your script. aCSTV was designed to make sure to clean up and close all its background tasks on its own, if the GUI window was closed. So I’m a bit concerned what happens if your script tries to shut down the MPV window separately the same time aCSTV itself shuts down this very MPV instance already. This will need some testing to make your script run reliable. The behaviuor of your script to close down all windows from the wm list without caring for their child or background processes could be easily an issue for other scripts or programs as well.

                  When adding the exception to your code, be aware there are multiple aCSTV-…tmp files present in /dev/shm while running, the significant part you’ll have to check for is the last two digits of the .tmp filename starting with „aCSTV-”, reading „05”.

                  Windows is like a submarine. Open a window and serious problems will start.

                  #105736
                  Member
                  Lead Farmer
                    Helpful
                    Up
                    0
                    ::

                    Hi @robin thanks for the suggestion, I didn’t find a recording package with the name “aCST” in the repos.
                    Not all programs will close when the script it running, for example if you didn’t save a file with a text editor like geany, you get a massage to save the document.

                    You can check if the temp file temp exist and use the exception name EXCP=”aCSTV” to exclude aCSTV.

                    ACST=$(grep -r "aCSTV" /dev/shm/)
                    if [[ "$ID" != "$EXCPID" && -n $ACST ]]; then
                        wmctrl -i -c $ID
                      fi

                    But you can add other apps that may kill running processes, so I thing it’s up to user to add them.

                    I will post a new version soon with an exception of “Package Installer” and “Synaptic Package Manager” to prevent killing a running update.

                    • This reply was modified 1 day, 21 hours ago by Lead Farmer.
                    • This reply was modified 1 day, 21 hours ago by Lead Farmer.
                    • This reply was modified 1 day, 21 hours ago by Lead Farmer.
                    #105746
                    Member
                    Lead Farmer
                      Helpful
                      Up
                      1
                      ::

                      Close all windows 1.2

                      1) Add exception of antiX – Updater, Synaptic Package Manager, Package Installer and antiX – autoremove, will not close when running the script.

                      2) Add your own exception, for example tint2 terminal.

                      # and an exception 
                      EXCP="tint2"
                      EXCP_ID=$(wmctrl -l | grep -i "$EXCP" | tail -1 | awk '{print $1}')
                      • This reply was modified 1 day, 22 hours ago by Lead Farmer.
                      • This reply was modified 1 day, 22 hours ago by Lead Farmer.
                      #105782
                      Member
                      Robin
                        Helpful
                        Up
                        0
                        ::

                        I didn’t find a recording package with the name “aCST” in the repos.

                        Please see:
                        https://www.antixforum.com/forums/topic/acstv-update-to-new-version-1-09-fit-for-antix23/

                        aCSTV (antiX Community Simple TV starter) is still just not in the repos by now, so you need to follow the install instructions given in the thread.

                        You can check if the temp file temp exist and use the exception name EXCP=”aCSTV” to exclude aCSTV.

                        This would exclude aCSTV even when not running a recording, but just playing TV, while the exclusion is actually only needed when a recording is running. So a bit of regex pattern magic will be needed to differenciate the aCSTV temp files. Only the one ending with „05” is significant for recording. I believe this is not a task a normal user would be able to add to your script, so I think best is you provide readymade presets for at least the programs commonly used in antiX, so the user can add them easily without needing to know about all the regex stuff.

                        Try instead:
                        ls /dev/shm | grep aCSTV-[[:digit:]]*05.tmp
                        Not sure whether I did it right, there are multiple different regex syntaxes specific for the different tools. Maybe I’ve mixed up the grep regex syntax with the sed regex syntax or the geany in-document search regex syntax… Please check yourself.

                        Windows is like a submarine. Open a window and serious problems will start.

                        #105810
                        Member
                        Lead Farmer
                          Helpful
                          Up
                          0
                          ::

                          @Robin please test this:

                          #!/bin/bash
                          #
                          # Close all windows 1.3
                          #
                          
                          WINDOWS_ID=$(wmctrl -l | awk '{print $1}')
                          NUMBER_WINDOWS=$(wmctrl -l | wc -l)
                          EXCP_ID="NULL"
                          UPDATE_ID="NULL"
                          ACSTV_ID="NULL"
                          
                          # Check if an updater/installer is running
                          UPDATE=$(wmctrl -l | grep 'antiX - Updater\|Synaptic Package Manager\|Package Installer\|antiX - autoremove')
                          if [[ -n $UPDATE ]]; then
                          	UPDATE_ID=$(wmctrl -l | grep -i "$UPDATE" | tail -1 | awk '{print $1}')
                          fi
                          
                          # aCSTV is recording
                          ACSTV=$(ls /dev/shm | grep -Po 'aCSTV-\d+\.tmp')
                          if [[ -n $ACSTV ]]; then
                          	ACSTV_ID=$(wmctrl -l | grep -i "aCSTV" | tail -1 | awk '{print $1}')
                          fi
                          
                          # and an exception
                          #EXCP="id name"
                          #EXCP_ID=$(wmctrl -l | grep -i "$EXCP" | tail -1 | awk '{print $1}')
                          
                          for ((i = 1 ; i <= $NUMBER_WINDOWS ; i++)); do
                            ID=$(echo "$WINDOWS_ID" | head -$i | tail +$i)
                            if [[ "$ID" != "$UPDATE_ID" && "$ID" != "$ACSTV_ID" && "$ID" != "$EXCP_ID" ]]; then
                              wmctrl -i -c $ID
                            fi
                          done
                          
                          exit 0
                          #105817
                          Member
                          Robin
                            Helpful
                            Up
                            0
                            ::

                            @lead-farmer :
                            Unfortunately your command excludes aCSTV even when not recording. See the following sample output:

                            aCSTV started, neither playing nor recording:

                            $ ls /dev/shm | grep -Po 'aCSTV-\d+\.tmp'
                            aCSTV-195866501.tmp
                            aCSTV-195866502.tmp
                            aCSTV-195866503.tmp
                            aCSTV-195866506.tmp
                            aCSTV-195866507.tmp
                            aCSTV-195866508.tmp
                            aCSTV-195866509.tmp
                            aCSTV-195866512.tmp
                            aCSTV-195866515.tmp
                            aCSTV-195866518.tmp
                            aCSTV-195866519.tmp
                            
                            $ ls /dev/shm | grep aCSTV-[[:digit:]]*05.tmp
                            (no output)

                            aCSTV playing a TV station:

                            $ ls /dev/shm | grep -Po 'aCSTV-\d+\.tmp'
                            aCSTV-195866501.tmp
                            aCSTV-195866502.tmp
                            aCSTV-195866503.tmp
                            aCSTV-195866504.tmp
                            aCSTV-195866506.tmp
                            aCSTV-195866507.tmp
                            aCSTV-195866508.tmp
                            aCSTV-195866509.tmp
                            aCSTV-195866510.tmp
                            aCSTV-195866511.tmp
                            aCSTV-195866512.tmp
                            aCSTV-195866515.tmp
                            aCSTV-195866518.tmp
                            aCSTV-195866519.tmp
                            
                            $ ls /dev/shm | grep aCSTV-[[:digit:]]*05.tmp
                            (no output)

                            As you can see, there is now an additional file ending with the two digits „11”, which stands for playback mode.

                            aCSTV recording a stream:

                            $ ls /dev/shm | grep -Po 'aCSTV-\d+\.tmp'
                            aCSTV-195866501.tmp
                            aCSTV-195866502.tmp
                            aCSTV-195866503.tmp
                            aCSTV-195866504.tmp
                            aCSTV-195866505.tmp
                            aCSTV-195866506.tmp
                            aCSTV-195866507.tmp
                            aCSTV-195866508.tmp
                            aCSTV-195866509.tmp
                            aCSTV-195866510.tmp
                            aCSTV-195866512.tmp
                            aCSTV-195866515.tmp
                            aCSTV-195866518.tmp
                            aCSTV-195866519.tmp
                            
                            $ ls /dev/shm | grep aCSTV-[[:digit:]]*05.tmp
                            aCSTV-195866505.tmp

                            As you can see, the file ending with the digits „05” stands for recording mode, which is the one actually in need to exclude. And you can see the difference in output between the command you’ve used and my proposal for the grep regex.

                            Windows is like a submarine. Open a window and serious problems will start.

                            #105820
                            Member
                            Lead Farmer
                              Helpful
                              Up
                              0
                              ::

                              @Robin so if the file end with “05” it mean that is recording? edit: I missed that part.

                              If so is the script work if change it, douse it exclude aCSTV when recording?
                              ls /dev/shm | grep -Po 'aCSTV-\d+05\.tmp
                              or yours
                              ls /dev/shm | grep aCSTV-[[:digit:]]*05.tmp

                              • This reply was modified 1 day, 4 hours ago by Lead Farmer.
                              #105823
                              Member
                              Robin
                                Helpful
                                Up
                                1
                                ::

                                @lead-farmer Two times yes:
                                – Yes you’ve got it. The presence of its temp file ending with the digits „05” in /dev/shm means aCSTV is currently recording, (while the file ending with the digits „11” means aCSTV is currently playing a TV stream)

                                – Yes, I can confirm both commands from your latest posting work equivalent catching the proper flag file for the aCSTV recording mode. So I guess you can use
                                ls /dev/shm | grep -Po 'aCSTV-\d+05\.tmp'
                                within your script to properly catch the recording condition.

                                Windows is like a submarine. Open a window and serious problems will start.

                                #105824
                                Member
                                Lead Farmer
                                  Helpful
                                  Up
                                  0
                                  ::

                                  Close all windows 1.4

                                  Exclude aCSTV when recording.

                                Viewing 15 posts - 1 through 15 (of 15 total)
                                • You must be logged in to reply to this topic.