Author Topic: Various shutdown options on exit in Linux  (Read 258 times)


  • Jr. Member
  • **
  • Posts: 11
    • View Profile
Various shutdown options on exit in Linux
« on: December 13, 2020, 04:18:03 PM »
I was looking for a solution where I could have various shutdown options when exiting AM, like you get with Retropie / Emulation Station, where you can choose to shutdown, restart, exit do desktop, etc.
After a lot of searching, I didn't really find a suitable solution other than adding something to the Exit Command in AM.
I came up with the idea of running a shell script with a basic menu in it and putting it in the Exit command, but it didn't work. AM just locked up on exit and I would have to kill the AM process.
I then tried adding attract to the begining of the script to launch AM then when it exits then run the menu and running that when the OS started.
This worked when run from a terminal window, but when I launched it at startup, when AM exited, it didn't run the menu.
I have now found a solution that works, so thought i would share it in case anyone else wants to do a similar thing.

I'm running Ubuntu, so if you are using a different version of Linux, you may have to modify things slightly to get it to work.

So first of all I made the script, which has 3 options - Exit to desktop, reboot & shutdown. But you can obviously add more.

I called it and put it in the root of my home directory (in my case /home/sf)
The script uses dialog to make the menu, so if you don't have it, you will need to install it - sudo apt install dialog

to make the script

sudo nano

copy this into it

Code: [Select]


MENU="Choose one of the following options:"

         2 "SHUT DOWN MACHINE"
         3 "RESTART MACHINE")

CHOICE=$(dialog --clear \
                --backtitle "$BACKTITLE" \
                --title "$TITLE" \
                --menu "$MENU" \
                $HEIGHT $WIDTH $CHOICE_HEIGHT \
                "${OPTIONS[@]}" \
                2>&1 >/dev/tty)

case $CHOICE in
            echo ""
            sudo shutdown now
            sudo reboot

Now in the ubuntu desktop, go to your applications and select 'startup applications'
If you already have attract mode in there, you will need to remove it or untick it.
Click the Add button and give it a name. Then in the command option type
gnome-terminal --full-screen --hide-menubar --command /home/sf/
** replace sf with your user directory name **
Then click save

What this does on startup is, open a terminal window and run the script which launches AM then runs the menu when AM exits.
The terminal is run full screen and has the menu bar disabled.

inadvertently, this has also solved another issue I had where, during startup and when launching a game, the Ubuntu desktop would show for a brief second. Now it just shows the terminal screen.

Hope this is of some use to some people.
« Last Edit: December 13, 2020, 04:20:49 PM by Whoremoan »


  • Hero Member
  • *****
  • Posts: 634
    • View Profile
Re: Various shutdown options on exit in Linux
« Reply #1 on: December 14, 2020, 01:17:44 AM »
in AM, you can add a command, that starts after exit dialouge of AM.

start AM > press TAB key > General > Exit command : poweroff
exit AM
start AM again

It think, if you want to run it with sudo, the current user needs specific privileges to run it with sudo (otherwise linux waits for input of password for sudo).

in AM exists a Utility Menu. There you can add your commands, start another .nut files and so on

start AM > press TAB key > Plug-Ins > UtilityMenu

Enabled : Yes
Control : for example U
Item 1 Menu Text : Reboot
Item 1 Command : init 6

press the U button in game selection/display, a menu appears with your commands.
AM Version : 2.6.1
Input : Mad Catz Brawlstick; Mouse; Keyboard; Xbox360 Wireless
Cabinet : Yes
OS : Windows10 Pro
System : Dell Precision T3500 ; Intel X5650 ; 12GB RAM