Differences
This shows you the differences between two versions of the page.
| launch_a_script_legacy [2023/10/21 03:26] – created atari | launch_a_script_legacy [2023/10/21 04:43] (current) – remove redundancy atari | ||
|---|---|---|---|
| Line 84: | Line 84: | ||
| ===== Watch for a game start/stop event ===== | ===== Watch for a game start/stop event ===== | ||
| - | Batocera **5.23** and higher supports running a script right before a game launches and/or after a game is exited. Here are some examples: | + | <WRAP center round info> |
| - | * Automatic controller setup | + | This still functions |
| - | * Automatic scraping for new games | + | |
| - | * Change screen resolution (though it might be better to use switchres for this) | + | |
| - | * Sync savestates to an external/ | + | |
| - | * ... give me your idea here | + | |
| - | + | ||
| - | Place an executable script (can have any filename) with the correct [[https:// | + | |
| - | + | ||
| - | <WRAP center round important> | + | |
| - | Game start/stop event scripts must be marked as executable with the '' | + | |
| - | + | ||
| - | < | + | |
| - | # Open up a text editor | + | |
| - | nano / | + | |
| - | # Write in your script, save and exit. | + | |
| - | # Then to add the executable bit to it: | + | |
| - | chmod +x / | + | |
| - | </ | + | |
| - | + | ||
| - | This means that if your userdata partition is of the NTFS, exFAT or older file system that are missing the executable bit functionality, | + | |
| </ | </ | ||
| - | |||
| - | 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 argument parsed in the script have either of these flags: | ||
| - | |||
| - | * '' | ||
| - | * '' | ||
| - | |||
| - | **If you do not set cases for first argument, then the script is executed on every start and on every end of a game.** | ||
| - | |||
| - | ==== What is parsed ==== | ||
| - | |||
| - | Table of parsed arguments in correct order and their functions: | ||
| - | |||
| - | ^ Arg no. ^ Parsed Parameter | ||
| - | | | ||
| - | | | ||
| - | | | ||
| - | | | ||
| - | | | ||
| - | |||
| - | ==== Simple game start/stop script as an example ==== | ||
| - | |||
| - | At first create the directory where the scripts need to be set up. [[access_the_batocera_via_ssh|Connect through SSH]] and type '' | ||
| - | |||
| - | Here's the template script: | ||
| - | |||
| - | <code bash| first_script.sh> | ||
| - | #!/bin/bash | ||
| - | # This is an example file of how gameStart and gameStop events can be used. | ||
| - | |||
| - | # It's good practice to set all constants before anything else. | ||
| - | logfile=/ | ||
| - | |||
| - | # Case selection for first parameter parsed, our event. | ||
| - | case $1 in | ||
| - | gameStart) | ||
| - | # Commands in here will be executed on the start of any game. | ||
| - | echo " | ||
| - | echo " | ||
| - | ;; | ||
| - | gameStop) | ||
| - | # Commands here will be executed on the stop of every game. | ||
| - | echo " | ||
| - | ;; | ||
| - | esac | ||
| - | </ | ||
| - | |||
| - | Now you can see a log file created ''/ | ||
| ===== EmulationStation scripting ===== | ===== EmulationStation scripting ===== | ||
| - | In case Batocera' | + | EmulationStation |
| - | <WRAP center round important> | + | ===== Real use cases ===== |
| - | All EmulationStation scripts must be marked as executable with the '' | + | |
| - | <code> | + | <WRAP center round tip> |
| - | # Open up a text editor to create your script: | + | Only the older script |
| - | nano / | + | |
| - | # Write in your script, | + | |
| - | # Then to add the executable bit to it: | + | |
| - | chmod +x / | + | |
| - | </ | + | |
| - | + | ||
| - | This means that if your userdata partition is of the NTFS, exFAT or older file system that are missing the executable bit functionality, | + | |
| </ | </ | ||
| - | |||
| - | ^ Event name ^ Arguments ^ Notes ^ | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | |||
| - | EmulationStation sends different arguments to these scripts based on the event type. For game-related events: | ||
| - | |||
| - | ^ Arg no. ^ Parsed parameter ^ Usage ^ | ||
| - | | 1 | '' | ||
| - | | 2 | '' | ||
| - | | 3 | '' | ||
| - | |||
| - | <WRAP center round todo> | ||
| - | All events need to be added here. | ||
| - | </ | ||
| - | |||
| - | |||
| - | ==== Simple EmulationStation script example ==== | ||
| - | |||
| - | This script is an example of an EmulationStation '' | ||
| - | |||
| - | <file bash pixelcade.sh> | ||
| - | #!/bin/bash | ||
| - | |||
| - | # Save the arguments into variables. | ||
| - | system=" | ||
| - | rom=" | ||
| - | romname=" | ||
| - | |||
| - | # Convert an argument into another value. | ||
| - | if [[ " | ||
| - | system=" | ||
| - | fi | ||
| - | |||
| - | # Switch case for certain systems. | ||
| - | case ${system} in | ||
| - | fbneo) | ||
| - | system=" | ||
| - | ;; | ||
| - | scummvm) | ||
| - | rom=" | ||
| - | ;; | ||
| - | esac | ||
| - | |||
| - | # Execute this part every time this event triggers. | ||
| - | curl -G \ | ||
| - | --data-urlencode " | ||
| - | http:// | ||
| - | </ | ||
| - | |||
| - | ===== Real use cases ===== | ||
| - | |||
| - | ==== Batocera after boot scripts ==== | ||
| - | |||
| - | * [[https:// | ||
| - | <file bash custom.sh> | ||
| - | #!/bin/bash | ||
| - | while true; do | ||
| - | currenthour=$(date +%k%M) | ||
| - | if [ $currenthour -eq 2355 ]; then | ||
| - | shutdown -h now | ||
| - | fi | ||
| - | sleep 30 | ||
| - | done | ||
| - | </ | ||
| - | |||
| - | * Disable a specific network interface (e.g. '' | ||
| - | <file bash custom.sh> | ||
| - | #!/bin/bash | ||
| - | ifconfig eth1 down | ||
| - | </ | ||
| ==== Batocera event watcher scripts ==== | ==== Batocera event watcher scripts ==== | ||
| - | * [[https:// | ||
| - | <file bash outputsomething.sh> | ||
| - | #!/bin/bash | ||
| - | # by cyperghost for batocera | ||
| - | testfile="/ | ||
| - | echo "END Script!" | ||
| - | echo " | ||
| - | echo " | ||
| - | echo " | ||
| - | echo "ROM: $(basename " | ||
| - | [[ " | ||
| - | </ | ||
| * [[https:// | * [[https:// | ||
| Line 510: | Line 342: | ||
| exit 1 | exit 1 | ||
| - | </ | ||
| - | |||
| - | * [[https:// | ||
| - | <file bash shutdownsimple.sh> | ||
| - | #!/bin/bash | ||
| - | LED1=22 | ||
| - | LED2=27 | ||
| - | SHUTDOWN=3 | ||
| - | |||
| - | case " | ||
| - | start) | ||
| - | # LED init | ||
| - | echo " | ||
| - | echo " | ||
| - | echo out > / | ||
| - | echo 0 > / | ||
| - | echo out > / | ||
| - | echo 1 > / | ||
| - | |||
| - | #Button init | ||
| - | echo " | ||
| - | echo " | ||
| - | #This loop continuously checks if the shutdown button was pressed | ||
| - | #It sleeps as long as that has not happened. | ||
| - | buttonstate1=$(cat / | ||
| - | shutdownSignal=$(cat / | ||
| - | while [ $shutdownSignal = $buttonstate1 ]; do | ||
| - | shutdownSignal=$(cat / | ||
| - | sleep 0.5 | ||
| - | done | ||
| - | shutdown -h now | ||
| - | ;; | ||
| - | stop) | ||
| - | #unexport all GPIOs | ||
| - | #echo " | ||
| - | echo " | ||
| - | echo " | ||
| - | ;; | ||
| - | esac | ||
| - | exit $? | ||
| - | |||
| - | </ | ||
| - | |||
| - | * [[https:// | ||
| - | <file bash loadlatestsave.sh> | ||
| - | #!/bin/bash | ||
| - | |||
| - | # disable auto load/save state inside ES | ||
| - | # add ' | ||
| - | # to your batocera.conf | ||
| - | # by cyperghost aka lala for BATOCERA | ||
| - | # | ||
| - | # download this script to '/ | ||
| - | # | ||
| - | |||
| - | rom_no_ext=" | ||
| - | sav_path="/ | ||
| - | |||
| - | [[ " | ||
| - | [[ " | ||
| - | |||
| - | if [[ $1 == " | ||
| - | file=" | ||
| - | [[ -n " | ||
| - | [[ " | ||
| - | [[ -f " | ||
| - | cp -f " | ||
| - | fi | ||
| - | |||
| - | if [[ $1 == " | ||
| - | rm -f " | ||
| - | fi | ||
| - | |||
| - | </ | ||
| - | |||
| - | * Faff about with audio settings. | ||
| - | <file bash audio-shenanigans.sh> | ||
| - | case " | ||
| - | |||
| - | start) | ||
| - | # Get the current audio profile. | ||
| - | defaultprofile=" | ||
| - | # Get the current audio device. | ||
| - | defaultaudio=" | ||
| - | # Set the audio device to HDMI-2. | ||
| - | batocera-audio set HDMI-2 | ||
| - | # Set the default " | ||
| - | batocera-audio set-profile auto | ||
| - | | ||
| - | # Unmute the audio device. | ||
| - | batocera-audio setSystemVolume unmute | ||
| - | # Set audio level to 69. | ||
| - | batocera-audio setSystemVolume 69 | ||
| - | # Test the audio device with Mallet.wav | ||
| - | batocera-audio test | ||
| - | ;; | ||
| - | stop) | ||
| - | # Toggle the audio mute. | ||
| - | batocera-audio setSystemVolume mute-toggle | ||
| - | </ | ||
| - | |||
| - | ==== Batocera boot scripts ==== | ||
| - | |||
| - | === Delay Syncthing until after everything else === | ||
| - | |||
| - | <file bash boot-custom.sh> | ||
| - | #!/bin/bash | ||
| - | # Delay Syncthing until other boot stuff has completed. | ||
| - | |||
| - | if [[ " | ||
| - | if mv / | ||
| - | echo " | ||
| - | elif ls / | ||
| - | echo " | ||
| - | exit 0 | ||
| - | else | ||
| - | echo " | ||
| - | touch / | ||
| - | shutdown -h now | ||
| - | exit 1 | ||
| - | fi | ||
| - | fi | ||
| - | |||
| - | exit $? | ||
| - | </ | ||
| - | |||
| - | ==== EmulationStation scripts ==== | ||
| - | |||
| - | === Play a video on a second screen === | ||
| - | |||
| - | [[https:// | ||
| - | |||
| - | Place '' | ||
| - | |||
| - | <file bash game.sh> | ||
| - | #!/bin/bash | ||
| - | System=$1 #system name | ||
| - | Romname=${2%.*} #romname | ||
| - | rom=${Romname## | ||
| - | / | ||
| - | </ | ||
| - | |||
| - | Place '' | ||
| - | |||
| - | <file bash system.sh> | ||
| - | #!/bin/bash | ||
| - | System=$1 #System name | ||
| - | / | ||
| - | </ | ||
| - | |||
| - | Place '' | ||
| - | |||
| - | <file bash marquee.sh> | ||
| - | #!/bin/bash | ||
| - | |||
| - | case $1 in | ||
| - | Start) | ||
| - | Romname=$3 | ||
| - | Gamepath=$2 | ||
| - | marqueeimage=$Gamepath/ | ||
| - | if [ -f "/ | ||
| - | then | ||
| - | ffmpeg -i / | ||
| - | |||
| - | fi | ||
| - | |||
| - | if [ -f "/ | ||
| - | then | ||
| - | fbv / | ||
| - | elif [ -f " | ||
| - | then | ||
| - | fbv $marqueeimage -fer | ||
| - | else | ||
| - | fbv / | ||
| - | fi | ||
| - | |||
| - | ;; | ||
| - | Gameselected) | ||
| - | System=$2 #system name | ||
| - | Romname=$3 #romname | ||
| - | |||
| - | if [ -f "/ | ||
| - | then | ||
| - | fbv / | ||
| - | elif [ -f "/ | ||
| - | then | ||
| - | fbv "/ | ||
| - | else | ||
| - | fbv / | ||
| - | fi | ||
| - | |||
| - | ;; | ||
| - | |||
| - | Systemselected) | ||
| - | imagepath="/ | ||
| - | if [ -f " | ||
| - | then | ||
| - | fbv " | ||
| - | else | ||
| - | fbv / | ||
| - | fi | ||
| - | |||
| - | ;; | ||
| - | |||
| - | esac | ||
| - | </ | ||
| - | |||
| - | Place '' | ||
| - | |||
| - | <file bash script.sh> | ||
| - | #!/bin/bash | ||
| - | |||
| - | case $1 in | ||
| - | gameStart) | ||
| - | |||
| - | gamepath=${5%/ | ||
| - | romname=${5## | ||
| - | / | ||
| - | ;; | ||
| - | |||
| - | gameStop) | ||
| - | killall ffmpeg | ||
| - | ;; | ||
| - | esac | ||
| </ | </ | ||
- launch_a_script_legacy.1697858785.txt.gz
- Last modified: 3 years ago
- by atari