Another Simple Menu with .desktop file

July 10, 2020 - Reading time: 8 minutes

I wanted to make an interactive program/menu to launch some commands that I often use in terminal from Simple Bash Menu. I cleaned the old bash menu and directly put some part of the menu into a .desktop file alternative actions.

The desktop file is placed at ~/.local/share/applications/mymenu.desktop, it can then be searched from Start Menu, and easily attached to the Panel (taskbar). By attaching it to the Panel, the .desktop file itself can be clicked to launch the bash menu into Konsole, but right clicking it while it is attached to to Panel reveals some custom actions that I want accessible quickly.

Here is the initial mymenu.desktop file I created (edit: updated it since the article creation):

[Desktop Entry]
Name=My Menu
Comment=Application for managing My Menu
Exec=konsole --noclose -e ~/Scripts/menu.sh
Icon=face-glasses
Terminal=false
Type=Application
Actions=UPDATE;G400S;_SEPARATOR_;POWERSAVE;SCHEDUTIL;PERFORMANCE;_SEPARATOR_;SSHGAME;SSHVPS;SSHSCALEWAY;_SEPARATOR_;TEAMVIEWER;_SEPARATOR_;

[Desktop Action UPDATE] Name=System Update Icon=poedit-update Exec=konsole --noclose -e ~/Scripts/menu.sh -u

[Desktop Action G400S] Name=Reset G400S Icon=input-mouse-symbolic Exec=konsole -e sudo /usr/bin/evrouter -q; sudo /usr/bin/rm -f /tmp/.evrouter*; sudo /usr/bin/g400s_hack 3600 1; sudo /usr/bin/evrouter --config=/home/omano/.evrouterrc /dev/input/by-id/usb-Logitech_G400s_Optical_Gaming_Mouse-event-mouse; imwheel -k;

[Desktop Action SSHGAME] Name=SSH GAME Icon=utilities-terminal-symbolic Exec=konsole --noclose -e ssh omano@123.123.123.123

[Desktop Action SSHVPS] Name=SSH VPS Icon=utilities-terminal-symbolic Exec=konsole --noclose -e ssh root@123.123.123.123

[Desktop Action SSHSCALEWAY] Name=SSH SCALEWAY Icon=utilities-terminal-symbolic Exec=konsole --noclose -e ssh root@123.123.123.123

[Desktop Action TEAMVIEWER] Name=Teamviewer Icon=teamviewer-indicator Exec=konsole -e systemctl start teamviewerd.service; teamviewer; systemctl stop teamviewerd.service;

[Desktop Action POWERSAVE] Name=Power Save Icon=cpu Exec=sudo cpupower frequency-set -g powersave

[Desktop Action SCHEDUTIL] Name=Schedutil Icon=cpu Exec=sudo cpupower frequency-set -g schedutil

[Desktop Action PERFORMANCE] Name=Performance Icon=cpu Exec=sudo cpupower frequency-set -g performance

Here is the ~/menu.sh file (a stripped down version of the Simple Bash Menu) that is started directly when clicking the .desktop file face-glasses iconĀ  (or that auto-starts the system update process with the .desktop file menu entry), directly in Konsole:

#!/bin/bash
#
# Bash Menu 
#
# "sudo EDITOR=nano visudo" for NOPASSWD commands:
# 
## NOPASSWD commands full
#omano    ALL=(ALL)    NOPASSWD: /usr/bin/nvidia-smi
#omano    ALL=(ALL)    NOPASSWD: /usr/bin/nvidia-settings
#omano    ALL=(ALL)    NOPASSWD: /usr/bin/pacdiff
#omano    ALL=(ALL)    NOPASSWD: /usr/bin/cpupower
#omano    ALL=(ALL)    NOPASSWD: /usr/bin/nethogs
#omano    ALL=(ALL)    NOPASSWD: /usr/bin/iotop
#omano    ALL=(ALL)    NOPASSWD: /usr/bin/update-grub
#omano    ALL=(ALL)    NOPASSWD: /usr/bin/g400s_hack
#omano    ALL=(ALL)    NOPASSWD: /usr/bin/pacman
#omano    ALL=(ALL)    NOPASSWD: /usr/bin/pacman-mirrors
#omano    ALL=(ALL)    NOPASSWD: /usr/bin/input-remapper-control
## NOPASSWD commands match
##omano   ALL=         NOPASSWD: /usr/bin/rm -f /tmp/.evrouter*
##omano   ALL=         NOPASSWD: /usr/bin/killall evrouter
##omano   ALL=         NOPASSWD: /usr/bin/input-remapper-control --command stop --device "Logitech G400s Optical Gaming Mouse"
##omano   ALL=         NOPASSWD: /usr/bin/input-remapper-control --command start --device "Logitech G400s Optical Gaming Mouse" --preset "Default"
##omano   ALL=         NOPASSWD: /usr/bin/input-remapper-control --command start --device "Logitech G400s Optical Gaming Mouse" --preset "Games"
#
#

command lines arguments

while getopts u option do case "${option}" in u) screenfetch; echo; sudo /usr/bin/pacman-mirrors -c Global && sudo /usr/bin/pacman -Syyu; echo; echo "update process done..";exit;; *) echo "invalid flag detected.. exiting...";exit;; esac done

start of bash menu

clear screenfetch echo

PS3=' Please enter your choice: ' options=( "Pacman" "Wine Mime and co" "Quit") select opt in "${options[@]}" do case $opt in "Wine Mime and co") clear read -p "Clean WINE extensions and shit? " -n 1 -r echo if [[ $REPLY =~ ^[YyOo]$ ]] then rm -f ~/.local/share/applications/wine-extension.desktop rm -f ~/.local/share/icons/hicolor///application-x-wine-extension rm -f ~/.local/share/mime/packages/x-wine rm -f ~/.local/share/mime/application/x-wine-extension fi echo; ls ~/.local/share/applications/wine/Programs/ echo read -p "Clean WINE programs? " -n 1 -r echo if [[ $REPLY =~ ^[YyOo]$ ]] then rm -Rf ~/.local/share/applications/wine/Programs/ fi echo read -p "Delete useless dictionaries? " -n 1 -r echo if [[ $REPLY =~ ^[YyOo]$ ]] then sudo rm /usr/share/hunspell/en_US.aff sudo rm /usr/share/hunspell/en_US.dic sudo rm /usr/share/hunspell/fr_BE.aff sudo rm /usr/share/hunspell/fr_BE.dic sudo rm /usr/share/hunspell/fr_CA.aff sudo rm /usr/share/hunspell/fr_CA.dic sudo rm /usr/share/hunspell/fr_CH.aff sudo rm /usr/share/hunspell/fr_CH.dic sudo rm /usr/share/hunspell/fr_LU.aff sudo rm /usr/share/hunspell/fr_LU.dic fi echo read -p "Rebuild mime info? " -n 1 -r echo if [[ $REPLY =~ ^[YyOo]$ ]] then rm -f ~/.local/share/applications/mimeinfo.cache update-desktop-database ~/.local/share/applications update-mime-database ~/.local/share/mime/ fi echo journalctl --disk-usage echo read -p "Clear journal logs? " -n 1 -r echo if [[ $REPLY =~ ^[YyOo]$ ]] then sudo journalctl --vacuum-size=256M fi echo; echo "cleaning job done.." break ;; "Pacman") clear PACBRANCH=$(pacman-mirrors --get-branch) echo "Current branch: $PACBRANCH"; echo; read -p "Change the branch? " -n 1 -r if [[ $REPLY =~ ^[YyOo]$ ]] then echo; echo; echo "Select the branch you want to use:" select answer in "STABLE" "TESTING" "UNSTABLE" "CANCEL"; do case $answer in "STABLE" ) echo; echo "switching to STABLE branch!"; echo; sudo pacman-mirrors -a -B stable; sudo pacman -Syyuu; echo; break;; "TESTING" ) echo; echo "switching to TESTING branch!"; echo; sudo pacman-mirrors -a -B testing; sudo pacman -Syyuu; echo; break;; "UNSTABLE" ) echo; echo "switching to UNSTABLE branch!"; echo; sudo pacman-mirrors -a -B unstable; sudo pacman -Syyuu; echo; break;; "CANCEL") echo; echo "Changing branch canceled. Kept current $PACBRANCH branch."; echo; break;; esac done echo "branch update process done.." break fi echo; echo read -p "Update mirrors? " -n 1 -r if [[ $REPLY =~ ^[YyOo]$ ]] then echo; echo; echo "Updating mirrors:"; echo; sudo pacman-mirrors --country Global fi echo; echo read -p "Update the system? " -n 1 -r if [[ $REPLY =~ ^[YyOo]$ ]] then echo; echo; echo "Select the tool you want to use:" select answer in "pacman" "pamac" "yay" "pacui" "mbn" "CANCEL"; do case $answer in "pacman" ) echo; echo; echo; sudo pacman -Syyu; echo; break;; "pamac" ) echo; echo; pamac upgrade -a; echo; break;; "yay" ) echo; echo; yay -Syyu; echo; break;; "pacui" ) echo; echo; pacui; echo; break;; "mbn" ) echo; echo; mbn update && mbn versions --testing --stable -v; break;; "CANCEL" ) echo; echo "canceled"; echo; break;; esac done fi pacnews=($(/usr/bin/pacdiff --output|grep -v pacsave)) nb="${#pacnews[@]}" if [[ $nb -gt 0 ]]; then echo; echo; echo -e "$nb .pacnew found in system" printf "%s\n" "${pacnews[@]}" echo; read -p "See the PacDiff? " -n 1 -r if [[ $REPLY =~ ^[YyOo]$ ]]; then echo; set -euo pipefail export PATH=/usr/bin:/usr/sbin for i in $(/usr/bin/pacdiff --output|grep -v pacsave); do echo; echo "Processing $i ..." /usr/bin/meld "admin://$i" "admin://${i/.pacnew/}" echo; read -p "Delete the file $i? " -n 1 -r if [[ $REPLY =~ ^[YyOo]$ ]]; then echo; sudo rm -v "$i" fi done fi fi echo; echo; echo "update process done.." break ;; "Quit") echo "exited.." break ;; ) echo "invalid option $REPLY";; esac done