#!/bin/bash
####GUI script to add a quicklauncher icon to JWM or IceWM toolbar, by PPC and Dave, GPL licence

###Get name of currently used Window Manager
desktop=$(wmctrl -m)
[[ $desktop = *"JWM"* ]]&& desktop=JWM
[[ $desktop = *"icewm"* ]]&& desktop=icewm

#Use app-select to make selection (as an app-select plug-in) 
     selected="$@"
     name="$2"
	 icon="$3"
	 executable="$4"
      
#If a selection was not done, exit
[[ $selected != *".desktop"* ]] && exit

#Process choice and add entry to JWM or IceWM toolbar- if none of this Window Managers is users, display warning and exit:
case "$desktop" in
    JWM)
        sed -i "/$name/d" ~/.jwm/tray
        #restart jwm to see changes
        jwm -restart 
    ;;
    icewm)
        #add icon to icewm toolbar
        sed -i "/$name/d"  ~/.icewm/toolbar
        #restart jwm to see changes
        icewm -r
   
    ;;
    *)
        yad --center --title="App-select" --text="No compatible window manager found: \n This script works only in IceWM and JWM"
        exit 1;
    ;;
esac
