Hello Pisound community, I’m trying to create a button script that will launch a python program. To run the program from the command line I have a short bash script: StartRig.sh that does the job as follows:
This script depends on the current working directory (the location from which it’s executed)
If you change the relative path Documents/python3_stuff/rig_FT232H.py into an absolute path like /home/patch/Documents/python3_stuff/rig_FT232H.py (if using Patchbox OS) or /home/pi/Documents/python3_stuff/rig_FT232H.py (if using Raspberry Pi OS, or just change the ‘pi’ to whatever is your main user), then it can be executed from any context. The pisound-btn scripts are executed from /root/ as the current working directory (often abbreviated as CWD).
Btw, the . at the start of the line is a synonym for source command as described here - it’s for ‘importing’ another script into the current one, so you can call some special functions defined in another script. In your case, you just want to execute your StartRig.sh script
So your StartRig.sh script should look like this:
#!/bin/sh
/usr/bin/python3 /home/patch/Documents/python3_stuff/rig_FT232H.py
# On OSes other than Patchbox OS, change 'patch' above into whatever is the main user on your system
Thank you for the explanation, I’ve edited the scripts as per your suggestion. The button is certainly running the program because the led flash operates but the python program does not…yet running the StartRig.sh script from the command line works fine…
You may be able to see some useful output that gets printed by your scripts in the journal:
Run:
journalctl -u pisound-btn -f
It will show the latest messages, so just press the button and see what output you get.
There’s some differences in the run context when scripts are executed from a systemd daemon - some required environment variables might be missing, it runs as different user (root), the current working directory might be different. You may try and add this line:
cd /home/patch
after the . /usr/local/pisound/scripts/common/common.sh line
But now a new challenge emerges. My python program runs with one click. I then want to launch Pure Data with a double click but nothing happens… the python program seems to block any further action from the button program until I kill the Python program. I can get round this by launching PD first, but that might sometimes be inconvenient. Can you think of an alternative?
Ah right, you should launch your script as a background job - this is done by adding a ‘&’ character at the end of a script line, so call your script as follows: