Page 1 of 2

How To: LXmenu Editor

Posted: Mon Jun 06, 2011 4:23 am
by Geert
Hello everyone,

Excuse my english, i'm from Argentina.
I've made a small script in bash to edit the lxmenu launchers, and i would like to share it with all of you.
Please, feel free to edit it or make corrections to it.

Here's the code:

Code: Select all


#!/bin/bash

#
# This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#################################################################################
#
# Contact: kameradklub@gmail.com
#

RUTA=(/usr/share/applications/*.desktop)
CONTADOR=0
IFS=":"

for i in "${RUTA[@]}"
do
	ACTUAL=${RUTA[$CONTADOR]}
	VERIFICAR=$(cat $ACTUAL | awk '/NoDisplay/ {print "1"}' )
	if [ "$VERIFICAR" != "1" ]; then
		printf "\n" >> $ACTUAL ; printf "NoDisplay=false" >> $ACTUAL
	fi
	let CONTADOR=$CONTADOR+1
done

CONTADOR=0

for b in "${RUTA[@]}"
do
	ACTUAL=${RUTA[$CONTADOR]}
	ARCHIVO=$(echo $ACTUAL | sed "s#/usr/share/applications/#""#")
	INVALOR=$(cat $ACTUAL | awk -F"=" '/NoDisplay/ {print $2} ' )
	NOMBRE1=$(cat $ACTUAL | awk -F"=" '/^Name=/ {print $2; exit}' | sed -e "s#[\ |:]#+#g")
	NOMBRE="'$NOMBRE1' + "
	if [ "$INVALOR" = "true" ]; then
		echo "+ false +"  >> lxcheckbox.txt
	fi
	if [ "$INVALOR" = "false" ]; then
		echo "+ true +"  >> lxcheckbox.txt
	fi
	sed -e '$s#$# '$NOMBRE# -i lxcheckbox.txt
	sed -e '$s#$# '$ARCHIVO# -i lxcheckbox.txt
	let CONTADOR=$CONTADOR+1
done
REMOVER=$(cat lxcheckbox.txt | tr -d '\ \n' | sed -e "s#+#\ #g")
echo $REMOVER > lxcheckbox.txt
CHECKBOX=$(cat lxcheckbox.txt)

echo $CHECKBOX > checkbox0.txt

OPCION=$(eval zenity --title=\"Edit LXMENU\" --width=300 --height=550 --list --checklist --multiple --column="Show" --column="Name" --column="File" $CHECKBOX --separator=":" )

OPCION1=($OPCION)
CONTADOR=0
CONTADOR1=0
ENCONTRADO=0

if [ "$OPCION1" != "" ]; then

	for c in "${RUTA[@]}"
	do
		ACTUAL=${RUTA[$CONTADOR]}
		ARCHIVO=$(echo $ACTUAL | sed "s#"/usr/share/applications/"#""#")
		VALOR=$(cat $ACTUAL | awk -F"=" '/NoDisplay/ {print $2} ' )
		NOMBRE=$(cat $ACTUAL | awk -F"=" '/^Name=/ {print $2; exit}' | sed -e "s#[\ |:]#\ #g")
	
		for d in "${OPCION1[@]}"
		do
			OPCION2=${OPCION1[$CONTADOR1]}
			if [ "$OPCION2" = "$NOMBRE" ]; then
			ENCONTRADO=1
			fi
			let CONTADOR1=$CONTADOR1+1
		done
		
		if [ "$ENCONTRADO" = "1" -a "$VALOR" = "true" ]; then
			sed -e 's/NoDisplay=true/NoDisplay=false/g' -i "$ACTUAL"
			
		fi
		
		if [ "$ENCONTRADO" = "0" -a "$VALOR" = "false" ]; then
			sed -e 's/NoDisplay=false.*/NoDisplay=true/g' -i "$ACTUAL"
		fi

		ENCONTRADO=0
		CONTADOR1=0
		let CONTADOR=$CONTADOR+1
	done
fi

rm lxcheckbox.txt


Enjoy! :)

Re: LXmenu Editor

Posted: Tue Jun 07, 2011 5:43 am
by seagradece
Awesome!

I've been using it to remove many unwanted icons from the menu that appear after software upgrades (such as libreoffice). It works great, it is super fast and easy.

Thanks!

Re: LXmenu Editor

Posted: Mon Jul 11, 2011 7:07 am
by mow_
ı m sorry.ı m new.what exactly do ı have to do to run this codes?

Re: LXmenu Editor

Posted: Mon Jul 11, 2011 9:31 pm
by ueltume
mow_ wrote:ı m sorry.ı m new.what exactly do ı have to do to run this codes?
Yeah, me too. I'm a beginner when it comes to writing and executing code.

Re: LXmenu Editor

Posted: Wed Aug 10, 2011 1:47 am
by Geert
Steps to run the code:

1º Create a text file called "lxmenu-editor.sh" and copy the code into it.
2º Give execute permission to it.
3º Execute it with this command: sh lxmenu-editor

If you see something like wrong names in the menu don't use it, just make click on "Cancel".
It's not a perfect script. It depends on wich ".desktop" files you have.

Re: How To: LXmenu Editor

Posted: Mon Sep 19, 2011 7:02 pm
by amjjawad
I have edited the subject to make it easier for everyone to search for it :)

Re: How To: LXmenu Editor

Posted: Tue Sep 27, 2011 7:57 pm
by vishcompany
Thanks a lot, Geert. Very useful script!

Re: How To: LXmenu Editor

Posted: Mon Oct 10, 2011 2:58 pm
by Geert
amjjawad wrote:I have edited the subject to make it easier for everyone to search for it :)
Thanks!
vishcompany wrote:Thanks a lot, Geert. Very useful script!
Glad to know it :)

Re: How To: LXmenu Editor

Posted: Mon Oct 10, 2011 3:04 pm
by amjjawad
Geert wrote:
amjjawad wrote:I have edited the subject to make it easier for everyone to search for it :)
Thanks!
Any time :)

Re: LXmenu Editor

Posted: Tue Nov 01, 2011 7:40 pm
by amjjawad
Geert wrote:Steps to run the code:

1º Create a text file called "lxmenu-editor.sh" and copy the code into it.
2º Give execute permission to it.
3º Execute it with this command: sh lxmenu-editor

If you see something like wrong names in the menu don't use it, just make click on "Cancel".
It's not a perfect script. It depends on wich ".desktop" files you have.
Hi,

I tried that but nothing happened when I try to run it. Lubuntu 11.04 here.

Code: Select all

sh: Can't open lxmenu-editor