Launch a script, one-shot, at boot time

Sometimes you just want to fire up one script at boot time, for example when you want to start up a VPN or other one-shot tasks. In oder to do this, you need to write a script /userdata/system/ This script is the very last one that will be invoked by Batocera at boot time.

Warning: make sure your script ends with Unix line terminators (LF), not Windows-style line terminators (CR/LF) otherwise the script will not launch. Use a real text editor to edit your scripts, especially if you edit them under Windows.

Scripting event on starting/ending a game

Since Batocera 5.23 we can execute scripts right before a game starts and after a game ends. There are several reasons for doing this.

  • Joypad setup
  • Automatic Scraping
  • Change screen resolution
  • Transfer Savestates to external device
  • … give me your idea here

Place an executable script with correct setted shebang (first line!) or an executable binary into directory /userdata/system/scripts.

You can add as many subfolders as you want, every script placed there will be executed. To distinguish between START or STOP condition the first arguments parsed to your script carries this information

  • gameStart is passed to your scripts if you select a game from EmulationStation (Game Starts!)
  • gameStop is passed to your scripts if you are going back from a game to EmulationStation (Game Stops!)

If you do not set cases for first argument, then the script is executed on every start and on every end of a game.

Table of parsed arguments in correct order and their functions:

Args. Parsed Parameter Usage
1 gameStart or gameStop to distinguish between START or STOP condition
2 systemName like in your es_system.cfg, for eg. atari2600
3 system.config['emulator'] The emulator settings, for eg. libretro
4 system.config['core'] The emulator core you have chosen, for eg. stella
5 args.rom The full rom path, for eg. /userdata/roms/atari2600/Mysterious Thief, A (USA).zip

At first create the directory where the scripts need to be set up. Connect through SSH and type mkdir /userdata/system/scripts. After this we can set up our first script by typing nano /userdata/system/scripts/

now fill in this code
#This is an example file how Events on START or STOP can be uses
#Set logfile location and filename
#Case selection for first parameter parsed
case $1 in
        echo "START" > $logfile
        echo "$@" >> $logfile
        echo "END" >> $logfile

Make the script executable with chmod +x /userdata/system/scripts/

Now you can see a log file created /tmp/scriptlog.txt, that parsed all arguments in this file. This is just a small test of course.

  • script_events_on_starting_ending_a_game.txt
  • Last modified: 10 months ago
  • by lbrpdx