This page contains a modified version of the script forming the core of the Menu system used by the guide Multipurpose Raspberry Pi: Installing a Media, Gaming, PC Replacement.
The revised code presented here modifies the menu to automatically launch an option after a configurable timeout period has elapsed; this is a workable, albeit admittedly elementary, solution to providing functionality which has been requested several times in the site’s comments sections.
To specify the timeout, in seconds, modify the following line:
TIMEOUTSECONDS=60
Specify the command to run after the timeout period elapses in the line following the comment:
# run desired default; match relevant command from the CASE statement, below
For example, to have the system launch the Desktop, set the value to:
startx
To launch the RetroPie emulation suite, set the value to:
emulationstation
To launch the Kodi Media Center, set the value to:
kodi
The creation and installation of this Menu system is detailed in the post Multipurpose Raspberry Pi – Part 2: Adding a Menu to Access RetroPie, Kodi, and the Raspbian Desktop
Menu Script Source Code Including Timeout Default Option
The following script can be copied directly from the web page and pasted into a text editor.
#!/bin/bash # Set number of seconds to elapse before a default command is executed TIMEOUTSECONDS=60 show_menu(){ NORMAL=`echo "\033[m"` MENU=`echo "\033[36m"` #Blue NUMBER=`echo "\033[33m"` #yellow FGRED=`echo "\033[41m"` RED_TEXT=`echo "\033[31m"` ENTER_LINE=`echo "\033[33m"` echo -e "${MENU}*********************************************${NORMAL}" echo -e "${MENU}**${NUMBER} 1)${MENU} StartX (Desktop) ${NORMAL}" echo -e "${MENU}**${NUMBER} 2)${MENU} Emulation Station (RetroPie) ${NORMAL}" echo -e "${MENU}**${NUMBER} 3)${MENU} Kodi ${NORMAL}" echo -e "${MENU}**${NUMBER} 4)${MENU} *Reboot* ${NORMAL}" echo -e "${MENU}**${NUMBER} 5)${MENU} *SHUTDOWN* ${NORMAL}" echo -e "${MENU}*********************************************${NORMAL}" echo -e "${ENTER_LINE}Please enter a menu option and enter or ${RED_TEXT}enter to exit. ${NORMAL}" echo -e "${ENTER_LINE}Default: Launch StartX after ${MENU}$TIMEOUTSECONDS seconds${NORMAL}" #read from standard input; timeout occurs after $TIMEOUTSECONDS seconds read -t $TIMEOUTSECONDS opt } function option_picked() { COLOR='\033[01;31m' # bold red RESET='\033[00;00m' # normal white MESSAGE=${@:-"${RESET}Error: No message passed"} echo -e "${COLOR}${MESSAGE}${RESET}" }
clear show_menu # check for exit code as a result of 'read' timeout if [[ $? -ne 0 ]] then echo -e "${MENU}Menu input - timeout triggered${NORMAL}" echo -e "${MENU}Launching X-Windows in 5 seconds ${NORMAL}" sleep 5 # run desired default; match relevant command from the CASE statement, below startx # re-load this script so the menu will be present after exiting from X-Windows back to the Terminal /home/pi/tools/selector.sh fi if [[ $opt = "" ]]; then exit; else case $opt in 1) clear; option_picked "Launching X-Windows"; startx # the main Terminal remains running whilst X-Windows loads on another process # re-load this script so the menu will be present after exiting from X-Windows back to the Terminal /home/pi/tools/selector.sh exit; ;;
2) clear; option_picked "Launching Emulation Station (RetroPie)"; emulationstation; /home/pi/tools/selector.sh exit; ;;
3) clear; option_picked "Launching Kodi Media Center"; kodi; /home/pi/tools/selector.sh exit; ;;
4) clear; option_picked "Rebooting System"; sudo reboot; ;;
5) clear; option_picked "Shutting Down System"; sudo shutdown -h now; ;;
*)clear; option_picked "Pick an option from the menu"; show_menu; ;; esac fi
About
Disclaimers
Privacy Policy
Terms and Conditions
© Retro Resolution