答案1
其实是一样的脚本。但没有面板删除部分。我还更改了删除面板到目标面板以避免混淆。
目标面板是要改变的面板的面板名称。
#!/bin/bash
PANEL_PATH="${HOME}/.mateconf/apps/panel"
TARGET_PANEL='bottom_panel_screen0'
echo 'DEBUG: Panel Path' ${PANEL_PATH}
echo 'DEBUG: Panel to be altered' ${TARGET_PANEL}
# - APPLETS
# -- Identify applet to be deleted
cd ${PANEL_PATH}/applets
DEL_APPLET=`grep -r ${TARGET_PANEL} *|cut -d\/ -f1`
echo 'DEBUG: DEL_APPLET' ; for i in ${DEL_APPLET} ; do echo -e "DEBUG: \t${i}" ; done
# -- Get old applet id list
APPLET_ID_LIST_OLD=`mateconftool-2 -g /apps/panel/general/applet_id_list | cut -d\[ -f2 | cut -d\] -f1 | sed 's/,/ /g'`
echo 'DEBUG: Old applet_id_list' ${APPLET_ID_LIST_OLD}
# -- Generate new applet id list
APPLET_ID_LIST_NEW=''
for i in ${APPLET_ID_LIST_OLD}
do
if [[ "$DEL_APPLET" != *"${i}"* ]]
then
echo -e "DEBUG: \tKeep ${i}"
APPLET_ID_LIST_NEW="${APPLET_ID_LIST_NEW} ${i}"
else
echo -e "DEBUG: \tDel ${i}"
# -- Delete applet folder
rm -rf ${PANEL_PATH}/applets/${i}
fi
done
APPLET_ID_LIST_NEW="[`echo ${APPLET_ID_LIST_NEW} | sed 's/ /,/g'`]"
# -- Apply new applet id list
mateconftool-2 -s /apps/panel/general/applet_id_list -t list --list-type=string "${APPLET_ID_LIST_NEW}"
echo 'DEBUG: New applet_id_list' `mateconftool-2 -g /apps/panel/general/applet_id_list`
# - OBJECTS
# -- Identify object to be deleted
cd ${PANEL_PATH}/objects
DEL_OBJECT=`grep -r ${TARGET_PANEL} *|cut -d\/ -f1`
echo 'DEBUG: DEL_OBJECT' ; for i in ${DEL_OBJECT} ; do echo -e "DEBUG: \t${i}" ; done
# -- Get old object id list
OBJECT_ID_LIST_OLD=`mateconftool-2 -g /apps/panel/general/object_id_list | cut -d\[ -f2 | cut -d\] -f1 | sed 's/,/ /g'`
echo 'DEBUG: Old object_id_list' ${OBJECT_ID_LIST_OLD}
# -- Generate new object id list
OBJECT_ID_LIST_NEW=''
for i in ${OBJECT_ID_LIST_OLD}
do
if [[ "$DEL_OBJECT" != *"${i}"* ]]
then
echo -e "DEBUG:\tKeep ${i}"
OBJECT_ID_LIST_NEW="${OBJECT_ID_LIST_NEW} ${i}"
else
echo -e "DEBUG:\tDel ${i}"
# -- Delete object folder
rm -rf ${PANEL_PATH}/objects/${i}
fi
done
OBJECT_ID_LIST_NEW="[`echo ${OBJECT_ID_LIST_NEW} | sed 's/ /,/g'`]"
# -- Apply new object id list
mateconftool-2 -s /apps/panel/general/object_id_list -t list --list-type=string "${OBJECT_ID_LIST_NEW}"
echo 'DEBUG: New applet_id_list' `mateconftool-2 -g /apps/panel/general/object_id_list`