Author Topic: How do I call a bash script from a button press in attract mode  (Read 3221 times)

kevmorrin

  • Newbie
  • *
  • Posts: 1
    • View Profile
Hi,

I am a retropie / attract mode noob so sorry in advance if I'm asking basic/stupid questions.

Basically I have two buttons on my arcade that I would like to use to higher and lower the volume.
I have written two bash scripts to do this using amixer but I do not know how to call these scripts from a button press in attract mode.

I've been looking online for this but to no avail, is there any chance somebody could point me in the right direction?

Thanks in advance,
Kevin

FYI: I am using a zero delay encoder to connect the arcade controls up (https://www.amazon.in/Easyget-Joystick-Raspberry-Retropie-Projects/dp/B01C5J5AJO)
« Last Edit: May 24, 2018, 12:57:44 PM by kevmorrin »

wrybread

  • Sr. Member
  • ****
  • Posts: 100
    • View Profile
Re: How do I call a bash script from a button press in attract mode
« Reply #1 on: May 30, 2018, 08:23:07 PM »
There might be an easier way, but here's how I do it:

Step 1) Make an Attract Mode plugin

Save this as "CustomCommand.nut" or whatever, in Attract Mode's /plugins folder:

Code: [Select]
local cmd = "$HOME/.attract/screensaver/mame_screensaver.py";

fe.add_signal_handler( "custom_signal" )
function custom_signal( signal )
{
if ( signal == "custom5" ) // HARD CODED TO CUSTOM5!
{
print ("Running my script!!!!");
system( cmd );
}
}

Edit the "cmd" above to the path for your script. Also edit the "custom5" for whatever command you're using in Step 3 below.

Step 2) Enable the plugin

In Attract Mode, go to Plugins and find your newly created plugin (called "CustomCommand" in the example above) and enable it.

Step 3) Map a button to it

In Attract Mode, go to Controls and scroll down to the "custom" controls and click it to set whatever button you want to run it. In the example above you'd scroll down to Custom5 and then associate whatever button with it.

Now pressing that button should execute that AM plugin, which will launch your script.



« Last Edit: May 30, 2018, 08:49:18 PM by wrybread »