Switch Between Application Suites on your Multipurpose Pi with Ease
In this article, which builds upon the preceding post Multipurpose Raspberry Pi: Installing a Media, Gaming, PC Replacement, I demonstrate the addition of a menu to allow easy switching between application suites.
Whilst the solution overall is relatively straightforward, I’ve gone into some depth in order that this post can serve as a general how-to guide, providing some insights into Bash shell scripts, including: installing scripts using the desktop GUI or command line tools; how the code file is made executable; automatically running a script after login, and after programs are exited by the user; and other related concepts.
Topics Covered in this Post
- Menu Design Requirements and Goals
Introducing the Menu Script
– a Bash script handling user input and launching of the appropriate application suite
– re-displaying the menu upon exit from the selected suite
Installing the Menu Script
– either using the Raspbian desktop, or
– via a remote SSH session
Marking the Script File as Executable
– either using the File Manger GUI, or the command line
Adding Code to Launch the Menu
– updating the .bashrc script to automatically run the menu when the Raspberry Pi first logs in
– preventing the menu from loading when Bash terminal windows are opened in the desktop, or when a remote SSH session is launched
Optional Command Line Alias
– adding a Bash command alias to allow simple manual launching of the menu script
Optionally Booting with Numlock On
– start the Bash terminal with Numlock enabled to aid menu option selection
Menu Design Requirements and Goals
As noted in the post detailing the installation of the Multipurpose Pi system, the RetroPie emulator system cannot be launched from the X-Windows Raspbian desktop GUI. This restriction forced the requirement that the Pi boot to the text-mode Bash terminal, which in turn required launching of a chosen application suite via typed commands:
startx for the Raspbian desktop,
kodi for the Kodi Media Center, and
emulationstation for RetroPie.
Whilst this wasn’t a major issue, I wanted a method to launch a given suite without having to type commands at the Bash terminal – ideally via a menu-driven selection system. Whilst this necessarily must be text-based, it is friendlier than facing a blank command prompt upon booting.
Furthermore, I wanted the menu to automatically run when the Pi boots to the terminal, and also to be re-displayed whenever the user closes one of the selected application suites (using Kodi‘s power button, Emulation Station‘s Quit submenu, or Raspbian desktop’s main menu Shutdown option):