Hide .desktop entries from app launcher

Since I use a pretty simple start menu that just displays all applications and a search bar underneath, it’s kind of a mess.

A lot of entries are programs I will never ever use, a lot are…sound plugins that have their own standalone .desktop entries for some reason? At first I considered just deleting those files but then I read that you can add NoDisplay=true to a .desktop file to hide it from application launchers, without needing to delete it altogether. So I wrote a script that can do that sort of automatically, and also undo it if needed. It has to be run in /usr/share/applications. ~/.local/share/applications has some .desktop files too but not enough to really make it worth it for me.

#!/bin/bash
#
# Hide certain applications from launcher
# Add .desktop filenames (without ".desktop") below to array
# launch this program as "./hide.sh unhide" to revert the changes

list=(  "avahi-discover" "bssh" "bvnc" "calf" "cups" "designer-qt4" "linguist-qt4"
	"assistant-qt4" "qdbusviewer-qt4" "winetricks" "echomixer" "envy24control"
	"..."
)

if [ "$1" != "runningasroot" ]; then
	sudo ./"$0" runningasroot "$1"
	exit
else
	if [ "$2 " == " " ]; then
		# HIDE APPLICATIONS
		for i in ${list[@]}; do
			echo "Hiding $i.desktop"
			# Does NoDisplay= line exist?
			grep -q "NoDisplay=" "$i".desktop
			if [ $? == 0 ]; then
				# Yes, edit it
				sed -i 's|NoDisplay=.*|NoDisplay=true|' "$i.desktop"
			elif [ $? == 1 ]; then
				# No, add it
				echo "NoDisplay=true" >> "$i.desktop"
			else
				echo "$i: grep error"
			fi
		done
	elif [ "$2" == "unhide" ]; then
		# UNHIDE APPLICATIONS
		for i in ${list[@]}; do
                        echo "Unhiding $i.desktop"
                        # Does NoDisplay= line exist?
                        grep -q "NoDisplay=" "$i.desktop"
                        if [ $? == 0 ]; then
                                # Yes, edit it
                                sed -i 's|NoDisplay=.*|NoDisplay=false|' "$i.desktop"
                        elif [ $? == 1 ]; then
                                # No, add it
				echo "NoDisplay=false" >> "$i.desktop"
                        else
                                echo "$i: grep error"
                        fi
                done
	else
		echo "Please read the script"
		exit
	fi
fi

I edited list=( ) here so that this page wouldn’t become too long, but I went and counted how many entries I actually have in that array and it’s…133. And most of them are standalone sound effects in the form of in.lsp_plug.lsp_plugins_comp_delay_mono. So that cleaned things up a little. The menu is kind of usable now.

Leave a comment

Design a site like this with WordPress.com
Get started