Graphical way to add new icons to IceWM tool bar (antiX 19)

Forum Forums General Software Graphical way to add new icons to IceWM tool bar (antiX 19)

  • This topic has 5 replies, 3 voices, and was last updated Aug 2-8:21 am by PPC.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #24973
    Member
    PPC

      Howdy.

      Trying to escape my Real Life problems I spent part of today searching on-line for a GUI way to add icons to the default IceWM desktop and finding none, took the matter into my own hands: I know nothing of scripting, but I patched together a tiny and ugly script that allows to instantly add a quick launch icon to IceWM toolbar.
      I believe this greatly improves IceWM daily usage for newbies (and lazy long time users as myself) and would be a great little addition to the Control Centre…

      Details:
      1- it works with both executable files and (kinda of works with) .desktop files. I decided to try using .desktop files because they are well known to even newbie Linux users. If using .desktop files, cli applications are not executable, also, the script tries to use as Exec file the name of the .desktop file (which can’t ever be always 100 correct)
      2- If I really knew scripting/programming I would find a way to extract the correct icon, exec and name from a .desktop file, because I don’t, my script uses, by default the same name as the exec or .desktop file as the toolbar icon’s “name”.
      3- I choose a default gears icon, for folks that don’t want to bother, at the moment, looking for the correct icon. The default icon folder I set, in antiX 19, has thousands of icons- if you click to add the icon and type part of the name of your app, you’ll probably have a nice icon to use, in a process that takes less than 10 seconds…

      EDIT: new and safer version of the script, that no longer alters existing toolbar entries!

      Now the script:

      Just create a “addicon.sh” file and paste this script there, save, and don’t forget to make executable:

      
      #!/bin/bash
      # Adds a new tool bar icon to IceWM desktop toolbar- antiX 19
      # By PPC, 25/7/2019, adapted from many, many on-line examples
      # No licence what so ever- feel free to improve/adapt this script
      # To dos:
      # 1-automaticaly search the right icon,
      # 2- use Exec from a .desktop file, instead of trying to use the desktop file as a exec- implies a re-write...
      
      DADOS=$(yad --center --title="Add new icon to IceWM toolbar" --form --field='Icon ( a GEARS icon is the default)':FL '/usr/share/icons/papirus-antix/24x24/apps/yast-runlevel.png' --field='.desktop or Executable file':FL '/usr/share/applications/antix' --text="Beta- If using a .desktop file, tries to extrapolate the right exec")
      ICONE=$(echo "$DADOS" | cut -d'|' -f1)
      COMANDO0=$(echo "$DADOS" | cut -d'|' -f2)
      #this strips any existing path from the name:
      COMANDO00=$(basename $COMANDO0)
      #this strips any existing .desktop from the name:
      REMOVE=".desktop"
      COMANDO=${COMANDO00//$REMOVE/}
      
      # error if no application selected- avoids creating empty icon on toolbar:
      if [ $COMANDO = "antix" ]; then 	yad --title='Warning' --text='Executable file not correct!' --timeout=3 --no-buttons
      	exit
      fi
      
      #create backup file before changes
      cp ~/.icewm/toolbar ~/.icewm/toolbar.bak
      #add line to toolbar, using Command also as Name
      echo "prog "\"${COMANDO}"\" "${ICONE}" "${COMANDO}""  >> ~/.icewm/toolbar
      #instantly restart IceWm so the new icon appears
      icewm --restart
      
      

      P.

      • This topic was modified 3 years, 9 months ago by PPC.
      #24976
      Forum Admin
      rokytnji
        Helpful
        Up
        0
        ::

        Cool Beans. I am used to using locate and which commands myself but I understand the need.

        Sometimes I drive a crooked road to get my mind straight.
        Not all who Wander are Lost.
        I'm not outa place. I'm from outer space.

        Linux Registered User # 475019
        How to Search for AntiX solutions to your problems

        #25029
        Moderator
        BobC
          Helpful
          Up
          0
          ::

          Interesting. I see you have figured out how to use Yad.

          It worked fine on mine with exception that I had to restart IceWM manually to get the icon to appear.

          #25108
          Member
          PPC
            Helpful
            Up
            0
            ::

            I see you have figured out how to use Yad.

            I’ve had a very basic YAD knowledge for a while now… It the lat 80’s, yearly 90’s I tried to dabble in BASIC (using a 48K ZX spectrum- Timex clone!!!) and the logic part of programming stuck- I may not know much programming, but I can read parts of it and understand what it does… So basically I googled each small function I had to perform and adapted it to my script…

            NEW (very basic) Toolbar Icon Managerr (TIM for short):
            -This new version, still a beta with maybe some hidden bugs, is meant to allow users to add, in a simple way, icons to the toolbar, using .desktop files. It tries to find the right icon, and the right exec, extracting that data from the file).
            It also works by drag and drop: you can open TIM, open the file manager in your .desktop file folder, drag it to the “choose .desktop” field of TIM’s window and click the “add” icon button, and it’s done! Almost as easy as simply dragging the .desktop to your toolbar directly!
            I added 2 useful functions: a restore button (TIM always saves a back up before trying to add/remove a icon) and a delete icon, that deletes the icon further to the right.
            It lacks the ability to reorganize icons, remove a certain icon or place the new icon in a certain place- it always deletes or add the last icon further to the right side, but it’s way better than just typing away text on the toolbar file.
            I find that the ability to reorganize icons is not meaningful- it’s way easier to open the toolbar file and move lines around that writing, from scratch, a new line, finding the right icon and the right executable file…
            Unfortunately, after today, I probably won’t be able to do further improvements to my script, but I documented everything in comments, so anyone that has better script programming skills than mine can improve it…

            @Anticapitalista- No one asked me, to do this, but I believe adding this script as the first icon in the Icewm toolbar file would be handy for most users- like Dave’s app-select script, this could become one more useful antiX extra, that, as far as I know, no other Distro has.
            Folks that don’t want it, don’t have to use it, and can happily type way on the toolbar config file… But having the script handy brings something most desktops already have- drag and drop a icon to the toolbar- without the need to use a (RAM eating) dock!

            EDIT- I forgot to upload the last change: when deleting icons, keep a mininum of lines (set in the mininumlines=11 variable), to avoid deleting important icons like the usb eject button, and, if TIM comes, out of the box in one of the first lines, avoid of the toolbar file, avoid deleting icon to TIM (that would leave newbies without a way to edit the toolbar after that deletion. More advanced users, of course, can manually edit the toolbar file)

            P.

            #!/bin/bash
            # Adds a new tool bar icon (from a .desktop file) to the IceWM desktop toolbar- antiX 19
            # By PPC, 25/7/2019, adapted from many, many on-line examplesv
            # No licence what so ever- feel free to improve/adapt this script
            # To do: 1- allow to list/move/delete icons from the toolbar (huge re-write- the app was meant originaly to add icons only, but I thought it was a nice way to allow some basic icon deletion funtions.
            
            DADOS=$(yad --length=800 --width=800 --center --paned --splitter="200" --title="Toolbar Icon Manager for IceWM BETA 2 " \
            --form --field='App .desktop file':FL '/usr/share/applications/antix' \
            --button=gtk-cancel:1 \
            --button="REMOVE last icon":2 \
            --button="Undo last change":3 \
            --button="ADD selected icon":0 \
            --wrap --text="Choose (or drag and drop to this field) the .desktop file you want to add to the toolbar OR any other option")
            
            ### wait for a button to be pressed then do the needed funtion
            foo=$?
            
            [[ $foo -eq 1 ]] && exit 0
            
            		###Function to delete last icon
            	
            if [[ $foo -eq 2 ]]; then
            
            			### Does not allow to remove the first $mininumlines "toolbar" file lines  -> meant to not allow delete the show desktop, eject usb and the TIM icons from the toolbar 
            			mininumlines=11
            			a=($(wc ~/.icewm/toolbar))
            			existinglines=${a[0]}
            			if [ "$mininumlines" -gt "$existinglines" ]; then  yad --title='Warning' --text='TIM is programed always keep 11 lines in the "toolbar" file! If you want to, do it manually!' --timeout=3 --no-buttons --center; exit
            			fi
            			###
            
            yad --title='Warning' --text='This will the delete the last icon to the right of your toolbar! Are you sure?' --center --button=gtk-cancel:1 \ --button=gtk-cancel:1 --button=gtk-yes:0 
              confirm=$?
              if [[ $confirm -eq 1 ]]; then exit
              fi
            
            #create backup file before changes
            cp ~/.icewm/toolbar ~/.icewm/toolbar.bak
            #TRY to Remove last icon on the toolbar
            BADLINESCOUNT=1
            ORIGINALFILE=~/.icewm/toolbar
            truncate -s $(printf "$(stat --format=%s ${ORIGINALFILE}) - $(tail -n${BADLINESCOUNT} ${ORIGINALFILE} | wc -c)\n" | bc ) ${ORIGINALFILE}
            #Restart ICewm to the change is instantly available
            icewm --restart
            	exit
            fi
            		###END of Function to delete last icon
            
            		###Function to restore last backup
            if [[ $foo -eq 3 ]]; then
            cp ~/.icewm/toolbar.bak ~/.icewm/toolbar
            icewm --restart
            exit 
            fi 
            		###END Function to restore last backup
            
            if [[ $foo -eq 0 ]]; then
            
            		###Function to add a new icon
            
            COMANDO0=$(echo "$DADOS" | cut -d'|' -f1)
            #this strips any existing path from the name:
            EXEC0=$(grep Exec= $COMANDO0 | cut -d '=' -f2)
            EXEC=$(echo "$EXEC0" | cut -f1 -d" ")
            #this strips any existing path from the name:
            COMANDO00=$(basename $COMANDO0)
            #this strips any existing .desktop from the name:
            REMOVE=".desktop"
            NOME=${COMANDO00//$REMOVE/}
             #try to find app icon:
            	ICON0=$(grep Icon= $COMANDO0 | cut -d '=' -f2)
            	ICON00=$(echo "$ICON0" | cut -f1 -d" ")
            	ICONwithoutpath=$(basename $ICON00)
            	ICON0=$(grep Icon= $COMANDO0 | cut -d '=' -f2)
            	ICON00=$(echo "$ICON0" | cut -f1 -d" ")
            	ICONwithoutpath=$(basename $ICON00)
            	path="/usr/share/icons/papirus-antix/24x24/apps/"
            	extension=".png"
            
            if [ "$ICON00" == "$ICONwithoutpath" ]; then
                ICONE=$path$ICONwithoutpath$extension
                ### CHECk IF ICONE exits in default Path
            else
                ICONE="/usr/share/icons/papirus-antix/24x24/apps/yast-runlevel.png"
            fi
              
              #IF ICON not found on that path, try other path and if still not found, use default  
            if [ -f "$ICONE" ]; then OK=OK
            else 
               path="/usr/share/pixmaps/"
               ICONE=$path$ICONwithoutpath$extension
                    if [ -f "$ICONE" ]; then OK=OK
            		else 
            		ICONE="/usr/share/icons/papirus-antix/24x24/apps/yast-runlevel.png"
            		fi
            fi
                
            # error if no application selected- avoids creating empty icon on toolbar:
            if [ -z "$EXEC" ]; then yad --title='Warning' --text='No changes were made! Please choose a application.' --timeout=3 --no-buttons --center
            	exit
            fi
            
            #create backup file before changes
            cp ~/.icewm/toolbar ~/.icewm/toolbar.bak
            
            #open .desktop file and get EXEC= contents
            EXEC0=$(grep Exec= $COMANDO0 | cut -d '=' -f2)
            #in case EXEC has more than one line, use only the first
            readarray -t lines < <(echo "$EXEC0")
            EXECperc="${lines[0]}"
            
            #add line to toolbar - the | cut -f1 -d"%"   part removes any %x option from the exec command.
            echo "prog "\"${NOME}"\" "${ICONE}" "${EXECperc}""| cut -f1 -d"%"  >> ~/.icewm/toolbar
            #instantly restart IceWm so the new icon appears
            icewm --restart
            		###END of Function to add a new icon
            
            exit
            
            fi
            
            
            • This reply was modified 3 years, 9 months ago by PPC.
            • This reply was modified 3 years, 9 months ago by PPC.
            • This reply was modified 3 years, 9 months ago by PPC.
            #25229
            Moderator
            BobC
              Helpful
              Up
              0
              ::

              PPC,

              What if there were toolbar icons in the file that were commented out with a “#prog ” in front? Let’s call them “Inactive”.

              Do you think you could figure an easy way “Activate” those inactive Icons by removing the # sign?

              That way the file could be supplied with standard “Active” icons, and other ones in the file, ready to go, with the right icons and commands, that someone could easily just Activate or Deactivate…

              Just thinking aloud…. Here is my toolbar file…

              # This is a default toolbar definition file for IceWM
              #
              # Place your personal variant in $HOME/.icewm directory.
              
              ### Commonly used applications
              #prog "Control Centre" /usr/share/icons/papirus-antix/48x48/apps/control-center2.png antixcc.sh
              prog "Unplug Removable Device" /usr/share/icons/papirus-antix/48x48/devices/drive-removable-media-usb.png unplugdrive.sh
              #prog "Volume Control" /usr/share/icons/Faenza-Cupertino-mini/apps/48/alsamixer-equalizer.png x-terminal-emulator -e alsamixer
              #prog "WiFi Setup" /usr/share/icons/antix-papirus/connman.png connman-gtk
              #prog "Terminal" /usr/share/icons/papirus-antix/48x48/apps/terminal.png desktop-defaults-run -t
              prog "File Manager" /usr/share/icons/papirus-antix/48x48/apps/file-manager.png desktop-defaults-run -fm
              #prog "Screenshot" /usr/share/icons/papirus-antix/48x48/apps/gnome-screenshot.png antixscreenshot.sh
              #prog "Editor" /usr/share/icons/papirus-antix/48x48/apps/text-editor.png desktop-defaults-run -te
              prog "Web Browser" /usr/share/icons/papirus-antix/48x48/apps/web-browser.png desktop-defaults-run -b
              prog "App Selector" /usr/share/icons/papirus-antix/48x48/apps/applications.png app-select
              
              #25250
              Member
              PPC
                Helpful
                Up
                0
                ::

                Do you think you could figure an easy way “Activate” those inactive Icons by removing the # sign?

                Maybe- on the notes I took how to parse text files, probably I could produce a script that:
                -reads the toolbar file line by line
                – checks if a line starts with “# prog” and then read the name of the app
                – put that info on a yad window, with a check box, to allow the “activation” of active windows…
                – then replace the begining of the choosen “#prog” lines with only “prog”
                But doing that implies processing the intire toolbar file, which I didn’t tackle, because of the complexity of doing that- I basically tought myself bash scripting using on-line examples, adapting them to every single function I wanted to do… That’s why my script only adds or deletes the last line from the toolbar folder, and does not allow, for example, moving icons around or delete arbitrary icons…- my last “release”, has one addiction- a “manage icons”- that displays a short how to, teaching even a newbie how to move/delete entries on the toolbar file and then pops open geany …toolbar for edition.
                I started this project only wanting to allow easy creation of new toolbar icons. Even now, for me, doing that is a chore, mainly finding the correct icon to display. Moving or “inativating” icons directly via the toolbar file edition is not a GUI way, but at least is something that’s very easy to do- I did that even before realizing how to dig around for the right icons…

                By the way-
                BUG: I never go to add the ability to launch cli applications to my script- as far as I know, it’s the only “bug”- it adds the icon to the toolbar, but does not add the right command to launch the application via the terminal– that probably should be in the short info my script displays in the main window. If someone whats to use it out of the box on antiX, please take care to add that warning (or solve the problem- adding a parsing option to see if the .desktop file app runs from the terminal and adapt the line that is added to the toolbar file to include the terminal…
                Unfortunately, for now I can no longer work on this little script… but I trust that even the way it is, it would be a nice addiction to the default antiX desktop…

                P.

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