Guest User

a guest
Sep 11th, 2019
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # Adds/Removes icons to the IceWM desktop toolbar- antiX 19(adding icons is done usinf the info from the app's .desktop file)
  3. # By PPC, 30/7/2019 - 11/9/2019 adapted from many, many on-line examples
  4. # No licence what so ever- feel free to improve/adapt this script
  5. # To do: 1- allow to list/move/delete icons from the toolbar (it implies a huge re-write)
  7. DADOS=$(yad --window-icon=gtk-add --length=800 --width=800 --center --paned --splitter="200" --title="Toolbar Icon Manager for IceWM v.851" \
  8. --form --field="   App's .desktop file:    ":FL '/usr/share/applications/antix' \
  9. --button="EXIT !/usr/share/icons/papirus-antix/22x22/actions/exit.png":1 \
  10. --button="HELP !/usr/share/icons/papirus-antix/22x22/actions/help.png":5 \
  11. --button="ADVANCED !/usr/share/icons/papirus-antix/22x22/actions/view-pim-journal.png":4 \
  12. --button="REMOVE icon!/usr/share/icons/papirus-antix/22x22/actions/xml-attribute-delete.png":2 \
  13. --button="UNDO !/usr/share/icons/papirus-antix/22x22/actions/undo.png":3 \
  14. --button="ADD icon!/usr/share/icons/papirus-antix/22x22/actions/add.png":0 \
  15. --wrap --text="  \n  Please select any option from the buttons below. \n  To add a new icon to the toolbar choose (or drag and drop to the field below) your applications's .desktop file \n   then click the 'ADD icon' button. \n ")
  17. ### wait for a button to be pressed then perform the selected funtion
  18. foo=$?
  20. [[ $foo -eq 1 ]] && exit 0
  22.         ###Function to display help
  23.         if [[ $foo -eq 5 ]]; then   yad --window-icon=gtk-add --title='Help - IceWM Toolbar Icon Manager' --wrap --text=" \n What is this? \n This utility allows basic icon adding and delection functionality to IceWm's toolbar. \n The toolbar application icons are created from an application's .desktop file.  \n  What are .desktop files? \n Usually a .desktop file is created during an application's instalation process, to allow the system easy access to relevant information, like the app's full name, commands to be executed, icon to be used, where it should be placed in the OS menu, etc. \n A .desktop file name usualy referes to the app's name, wich usually makes it very easy to find the intended .desktop file (ex: Firefox ESR's .desktop file is 'firefox-esr.desktop').\n When adding a new icon to the toolbar, the user can click the field presented in the main window and a list of all the .desktop files of the installed applications will be show. \n That, in fact, is a list of (almost) all installed applications, that can be added to the toolbar. \n Note: some of antiX's applications are found on the sub-fold 'antiX'. \n \n  TIM button's: \n 'ADD icon' - after selecting the .desktop file of the application you want to add to your toolbar, click this button and it instantly shows up on the toolbar. \n If, for some reason, TIM fails to find the correct icon for your application, it will still create a toolbar icon- using the default 'gears' picture, that you can still click to access the application.\n You can click the 'Advanced' button to manually edit the relevant entry and change the application's icon. \n  'UNDO' - every time a icon is added or removed from the toolbar, TIM creates a backup file. If you click this button, the toolbar is instantly restored from that backup file, without any confirmation. \n 'REMOVE icon' - this removes the icon that is on the further right side of the toolbar, it always asks for confirmation before doing this. As a safe guard this button can't delete below a certain number of icons. \n 'ADVANCED' - this option allows the edition of the text configuration file that has all of your desktop's toolbar icon's configurations. Manually editing this file allows the user to rearange the order of the icons and delete or add any icon. A brief explanation about the inner workings of the text configuration file is displayed before the file is open for edition. \n Warnings: only manually edit a configuration file if you are sure of what you are doing! Always make a back up copy before editing a configuration file! " --center --length=50 --width=600 --button=gtk-quit:1;
  24.     # now instead of exiting, TIM is reopen to allow for adding/deleting multiple icons sequentially without having to start TIM each time!  
  27.         fi
  28.         ###END of Function to display help
  30.         ###Function to manually manage icons (ADVANCED management)
  31.         if [[ $foo -eq 4 ]]; then   cp ~/.icewm/toolbar ~/.icewm/toolbar.bak && yad --center --form --title="Toolbar Icon manager" --field="Warning::TXT" " TIM has no 'graphical' way to allow users to move icons around or delete arbitrary icons.\n If you proceed, the toolbar configuration file will be open for edition.\n \n How-to: \n Each toolbar icon is identified by a line starting with 'prog' followed by the application name (if the application name includes spaces, always put the full name between quotes), icon location and the application executable file. \n Move or delete the intire line refering to each toolbar icon entry.\n Note: Lines starting with # are comments only and will be ignored.\n There can be empty lines.\n Save any changes and then restart iceWM.\n You can undo the last change from TIMs "Restore" button." --width=400 --height=360 --button=gtk-no:1 --button=gtk-yes:0 && geany ~/.icewm/toolbar
  32.         fi
  33.         ###END of Function to manually arrange icons
  35.         ###Function to delete last icon
  37. if [[ $foo -eq 2 ]]; then
  38.             ### 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
  39.             mininumlines=9
  40.             a=($(wc ~/.icewm/toolbar))
  41.             existinglines=${a[0]}
  42.             if [ "$mininumlines" -gt "$existinglines" ]; then  yad --window-icon=gtk-add --title='Warning' --text='  TIM is programed always keep 9 lines in the "toolbar" file! \n If you want to delete these icon, do it manually, using the ADVANCED button!  ' --timeout=3 --no-buttons --center; exit
  43.             fi
  44.             ###
  46. yad --window-icon=gtk-add --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
  47.   confirm=$?
  48.   if [[ $confirm -eq 1 ]]; then exit
  49.   fi
  51. #create backup file before changes
  52. cp ~/.icewm/toolbar ~/.icewm/toolbar.bak
  53. #TRY to Remove last icon on the toolbar
  55. ORIGINALFILE=~/.icewm/toolbar
  56. truncate -s $(printf "$(stat --format=%s ${ORIGINALFILE}) - $(tail -n${BADLINESCOUNT} ${ORIGINALFILE} | wc -c)\n" | bc ) ${ORIGINALFILE}
  57. #Restart ICewm to the change is instantly available
  58. icewm --restart
  59.     #exit
  60.     # now instead of exiting, TIM reopens to allow for adding/deleting multiple icons sequentially without having to start TIM each time!  
  62. fi
  63.         ###END of Function to delete last icon
  65.         ###Function to restore last backup
  66. if [[ $foo -eq 3 ]]; then
  67. cp ~/.icewm/toolbar.bak ~/.icewm/toolbar
  68. icewm --restart
  69. # now instead of exiting, TIM  reopens to allow for adding/deleting multiple icons sequentially without having to start TIM each time!  
  71. fi
  72.         ###END Function to restore last backup
  74. if [[ $foo -eq 0 ]]; then
  76.         ###Function to add a new icon
  78. COMANDO0=$(echo "$DADOS" | cut -d'|' -f1)
  79. #this strips any existing path from the name:
  80. EXEC0=$(grep Exec= $COMANDO0 | cut -d '=' -f2)
  81. EXEC=$(echo "$EXEC0" | cut -f1 -d" ")
  82. #this strips any existing path from the name:
  83. COMANDO00=$(basename $COMANDO0)
  84. #this strips any existing .desktop from the name:
  85. REMOVE=".desktop"
  87.  #try to find app icon:
  88.     ICON0=$(grep Icon= $COMANDO0 | cut -d '=' -f2)
  89.     ICON00=$(echo "$ICON0" | cut -f1 -d" ")
  90.     ICONwithoutpath=$(basename $ICON00)
  92. # By default set the icon as the gears icon, then look if the icon exist in several paths...
  93. ICONE="/usr/share/icons/papirus-antix/24x24/apps/yast-runlevel.png"
  95. # if a icon with a full path exists on the .desktop, use that icon
  96. if [[ -f "$ICON00" ]]; then  ICONE=$ICON00
  97. fi
  99. #...Also check if the icon's name exists in several possible default paths, if a existing icon is found, use that instead!
  100. #We can add as many paths as we want for the system to look for icons, also, we can look for icons with extensions other than .png (ex: svg), adding new "extension" and path's, and repeating the if-fi cicle
  102. extension=".png"
  104. path="/usr/share/pixmaps/"
  105. if [[ -f "$path$ICONwithoutpath$extension" ]]; then  ICONE=$path$ICONwithoutpath$extension
  106. fi
  108. path="/usr/share/icons/papirus-antix/24x24/apps/"
  109. if [[ -f "$path$ICONwithoutpath$extension" ]]; then  ICONE=$path$ICONwithoutpath$extension
  110. fi
  112. path="/usr/share/icons/papirus-antix/24x24/places/"
  113. if [[ -f "$path$ICONwithoutpath$extension" ]]; then  ICONE=$path$ICONwithoutpath$extension
  114. fi
  116. # error if no application selected- avoids creating empty icon on toolbar:
  117. if [ -z "$EXEC" ]; then yad --window-icon=gtk-add --title='Warning' --text="No changes were made! \n Please choose an  application's .desktop file to add it's icon the the toolbar." --timeout=3 --no-buttons --center
  118.     exit
  119. fi
  121. #create backup file before changes
  122. cp ~/.icewm/toolbar ~/.icewm/toolbar.bak
  124. #open .desktop file and get EXEC= contents
  125. EXEC0=$(grep Exec= $COMANDO0 | cut -d '=' -f2)
  126. #in case EXEC has more than one line, use only the first
  127. readarray -t lines < <(echo "$EXEC0")
  128. EXECperc="${lines[0]}"
  130. #add line to toolbar - the | cut -f1 -d"%"   part removes any %x option from the exec command.
  131. echo "prog "\"${NOME}"\" "${ICONE}" "${EXECperc}""| cut -f1 -d"%"  >> ~/.icewm/toolbar
  132. #instantly restart IceWm so the new icon appears
  133. icewm --restart
  134.         ###END of Function to add a new icon
  136. #exit
  137. # now instead of exiting, TIM reopens, to allow for adding/deleting multiple icons sequentially without having to start TIM each time!  
  140. fi
RAW Paste Data