# Modifying single\_click.sh scripts

**URL:** <https://community.blokas.io/t/modifying-single-click-sh-scripts/151>\
**Category:** Projects\
**Created:** [August 6, 2017, 1:27pm UTC](https://community.blokas.io/t/modifying-single-click-sh-scripts/151 "2017-08-06T13:27:52Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![carltesta](https://community.blokas.io/user_avatar/community.blokas.io/carltesta/32/71_2.png) [@carltesta](https://community.blokas.io/u/carltesta)\
**Post date:** [August 6, 2017, 1:27pm UTC](https://community.blokas.io/t/modifying-single-click-sh-scripts/151/1 "2017-08-06T13:27:52Z")

</div>

Hi All,

I’m awaiting my Pisound, should arrive tomorrow! I primarily use SuperCollider for audio projects and I’m looking for ways to autostart patches. Using Cronjob hasn’t been working for me. Could anyone give me any tips on how I could modify the single\_click.sh script to start jackd and run a supercollider patch instead of running Pure Data? The commands that I use to start up a patch are as follows:

export DISPLAY=:0.0  
/usr/bin/jackd -P75 -dalsa -dhw:1 -p1024 -n3 -s -r44100 &  
su root -c “sclang -D /home/pi/mycode.scd”

Thanks!  
Carl

---

<div class="post-metadata">

**Author:** ![Giedrius](https://community.blokas.io/letter_avatar_proxy/v4/letter/g/6a8cbe/32.png) [@Giedrius](https://community.blokas.io/u/Giedrius)\
**Post date:** [August 6, 2017, 5:00pm UTC](https://community.blokas.io/t/modifying-single-click-sh-scripts/151/2 "2017-08-06T17:00:20Z")

</div>

Hi Carl,

Clicking once will simply execute the `/usr/local/etc/pisound/single_click.sh` script as if you’d run it from shell yourself. So you could just replace it with your own script, or modify existing one - it’s not only starting Pure Data, but also does things like mounting attached USB media and connecting ALSA midi devices to the launched Pure Data instance.

The main line is this one: [https://github.com/BlokasLabs/pisound/blob/master/pisound-btn/single\_click.sh#L88](https://github.com/BlokasLabs/pisound/blob/master/pisound-btn/single_click.sh#L88)

The key thing is to have & at the end of the command - it causes it to start PD in background, so the button remains responsive.

The ‘nohup’ at the beginning is meant to keep the launched Pure Data running, even if the pisound-btn daemon gets killed. Otherwise, the child processes spawned by it would get terminated upon the daemons termination.

It’d be great to build a library of the button scripts customizations for different kinds of software, we’d definitely accept pull requests or ideas how to go about it. 🙂

---

<div class="post-metadata">

**Author:** ![carltesta](https://community.blokas.io/user_avatar/community.blokas.io/carltesta/32/71_2.png) [@carltesta](https://community.blokas.io/u/carltesta)\
**Post date:** [August 6, 2017, 9:41pm UTC](https://community.blokas.io/t/modifying-single-click-sh-scripts/151/3 "2017-08-06T21:41:42Z")

</div>

Thanks for the help! I’ll definitely try to create a modified script for SC. If it works then I’ll make a pull request with an additional file. Probably named single\_click\_SC\_patch.sh or something like that.

---

<div class="post-metadata">

**Author:** ![carltesta](https://community.blokas.io/user_avatar/community.blokas.io/carltesta/32/71_2.png) [@carltesta](https://community.blokas.io/u/carltesta)\
**Post date:** [August 6, 2017, 10:02pm UTC](https://community.blokas.io/t/modifying-single-click-sh-scripts/151/4 "2017-08-06T22:02:47Z")

</div>

Oh also, is there any kind of trick to setting an environment variable within a bash script? When I run a script that has “export DISPLAY=:0.0” in it, the variable doesn’t seem to get set. Do I need a different command?

When I test this, it seems like the variable is set, but within the wrong environment? Or that the variable is set but that the scope is local and thus doesn’t carry forward when the other commands are executed. Is there a way to set a global environment variable that will maintain it’s value once the script is complete?

---

<div class="post-metadata">

**Author:** ![Giedrius](https://community.blokas.io/letter_avatar_proxy/v4/letter/g/6a8cbe/32.png) [@Giedrius](https://community.blokas.io/u/Giedrius)\
**Post date:** [August 6, 2017, 10:20pm UTC](https://community.blokas.io/t/modifying-single-click-sh-scripts/151/5 "2017-08-06T22:20:21Z")

</div>

It depends on how the script gets executed - if it runs in its own shell process, it inherits the parent processes’ environment by copying it, and then it no longer has access to the process it was spawned from.

However, if you ‘source’ a shell script, it runs within the same process, so the environment variables that were set will be accessible from the same process and processes spawned later. If I remember right this can be done in two ways:

1. `. setenv.sh`
2. `source setenv.sh`

It’s similar to doing #include “…” in C/C++.

---

<div class="post-metadata">

**Author:** ![carltesta](https://community.blokas.io/user_avatar/community.blokas.io/carltesta/32/71_2.png) [@carltesta](https://community.blokas.io/u/carltesta)\
**Post date:** [August 7, 2017, 2:04am UTC](https://community.blokas.io/t/modifying-single-click-sh-scripts/151/6 "2017-08-07T02:04:33Z")

</div>

Thank You! The source command works. I expect it to be to pretty simple to get the script running once I have the Pisound. I’ll just have to change the click.sh script to run single\_click.sh with the source command as well. Really looking forward to diving into this.

---

<div class="post-metadata">

**Author:** ![oaulheslin](https://community.blokas.io/letter_avatar_proxy/v4/letter/o/74df32/32.png) [@oaulheslin](https://community.blokas.io/u/oaulheslin)\
**Post date:** [September 2, 2017, 11:26pm UTC](https://community.blokas.io/t/modifying-single-click-sh-scripts/151/7 "2017-09-02T23:26:25Z")

</div>

hey guys, sorry to bump an old thread but I’m looking to do this same thing.

I created my single\_click\_supercollider.sh in the scripts folder which looks like this:

> #!/bin/bash  
> /usr/local/bin/jackd -P75 -dalsa -dhw:1 -p1024 -n3 -s -r44100 &  
> sclang -D /home/pi/mycode.scd

I can trigger this from the command line with

> bash /usr/local/etc/pisound/single\_click\_supercollider.sh

and it works like a charm, but I am having problems getting the button to kick it off. Simply subbing in “single\_click\_supercollider.sh” instead of “single\_click.sh” in the “click.sh” does not seem to do it.

I’m guessing my issue is with the sclang command, that it needs to be wrapped and sent as either a su root or sudo su command, but I thought I would check in to see if anyone has had success on this front?

---

<div class="post-metadata">

**Author:** ![carltesta](https://community.blokas.io/user_avatar/community.blokas.io/carltesta/32/71_2.png) [@carltesta](https://community.blokas.io/u/carltesta)\
**Post date:** [September 3, 2017, 1:44am UTC](https://community.blokas.io/t/modifying-single-click-sh-scripts/151/8 "2017-09-03T01:44:16Z")

</div>

Hey there, so I don’t have my pisound yet, but I should hopefully get it next week. I think I have a method that should work but it will have to wait till I get a chance to test it. I’ll let you know next week.

Carl

---

<div class="post-metadata">

**Author:** ![oaulheslin](https://community.blokas.io/letter_avatar_proxy/v4/letter/o/74df32/32.png) [@oaulheslin](https://community.blokas.io/u/oaulheslin)\
**Post date:** [September 3, 2017, 2:37am UTC](https://community.blokas.io/t/modifying-single-click-sh-scripts/151/9 "2017-09-03T02:37:13Z")

</div>

too good, cheers for looking into it!

Paul

---

<div class="post-metadata">

**Author:** ![Giedrius](https://community.blokas.io/letter_avatar_proxy/v4/letter/g/6a8cbe/32.png) [@Giedrius](https://community.blokas.io/u/Giedrius)\
**Post date:** [September 3, 2017, 9:20am UTC](https://community.blokas.io/t/modifying-single-click-sh-scripts/151/10 "2017-09-03T09:20:35Z")

</div>

Hey, use 48000 for sampling rate, 44.1kHz is not supported natively by Pisound.

I think you should launch sclang in the background the same way as puredata is launched here:

[https://github.com/BlokasLabs/pisound/blob/master/pisound-btn/single\_click.sh#L91](https://github.com/BlokasLabs/pisound/blob/master/pisound-btn/single_click.sh#L91)

The `nohup` should keep the launched application running even if pisound-btn terminates and & at the end makes the command run in the background, so the control is returned to the button.

After triggering the script with the button you may try checking whether the sclang process is running using `ps -ef | grep sclang`

Also it does get launched as root user, on Raspbian Stretch, [these new lines](https://github.com/BlokasLabs/pisound/commit/8862cf2a81b130991b70a3ad6300662891f05ffe) had to be added to `single_click.sh` in order for the Pure Data GUI to appear for the user: [[SOLVED] Not working anymore: single click to launch Pd patch from USB](https://community.blokas.io/t/solved-not-working-anymore-single-click-to-launch-pd-patch-from-usb/196/10)

You may try adding those lines to your single click script.

---

<div class="post-metadata">

**Author:** ![carltesta](https://community.blokas.io/user_avatar/community.blokas.io/carltesta/32/71_2.png) [@carltesta](https://community.blokas.io/u/carltesta)\
**Post date:** [September 9, 2017, 5:45am UTC](https://community.blokas.io/t/modifying-single-click-sh-scripts/151/11 "2017-09-09T05:45:59Z")

</div>

Okay! Got my pisound today, yay! I’m able to get SuperCollider running when I manually run my script, but it doesn’t run when I replaced the single\_click.sh script in click.sh with my own script.

Could you tell me where the log command logs itself? I see this used in the pisound scripts, but I can’t find where this is logging to.

If I can find out if the script is throwing any errors then I can maybe figure out what is wrong.

Thanks,  
Carl

---

<div class="post-metadata">

**Author:** ![carltesta](https://community.blokas.io/user_avatar/community.blokas.io/carltesta/32/71_2.png) [@carltesta](https://community.blokas.io/u/carltesta)\
**Post date:** [September 9, 2017, 12:35pm UTC](https://community.blokas.io/t/modifying-single-click-sh-scripts/151/12 "2017-09-09T12:35:54Z")

</div>

When I add nohup to the command to start sclang I get the following message: “nohup: nohup: ignoring input and appending output to ‘/home/pi/nohup.out’ignoring input and appending output to ‘/home/pi/nohup.out’”

Any idea what this means?

Carl

---

<div class="post-metadata">

**Author:** ![carltesta](https://community.blokas.io/user_avatar/community.blokas.io/carltesta/32/71_2.png) [@carltesta](https://community.blokas.io/u/carltesta)\
**Post date:** [September 13, 2017, 2:49am UTC](https://community.blokas.io/t/modifying-single-click-sh-scripts/151/13 "2017-09-13T02:49:43Z")

</div>

Hi Everyone,

So I’m still trying to get a SuperCollider patch started after a single click from the Pisound button. The button is working and responding as expected (I’ve verified it’s working using the flash\_leds command in a script), but I cannot get Jack and SuperCollider to start. Here is my script:

#!/bin/bash  
. /usr/local/etc/pisound/common.sh  
. /usr/local/etc/pisound/display\_variable.sh  
flash\_leds 100  
sleep 3  
flash\_leds 100  
sleep 3  
flash\_leds 100  
sleep 3  
echo $DISPLAY  
/usr/bin/jackd -P75 -dalsa -dhw:1 -p64 -n3 -s -r48000 &  
echo “Starting Jackd”  
sleep 4  
flash\_leds 100  
sleep 3  
sclang -D /home/pi/mycode.scd &  
echo “Starting SuperCollider”  
flash\_leds 100

The lights flash correctly but Jack and SuperCollider do not start when I run this script from the button. If I run this script manually (by typing ./scstart.sh in the terminal) everything works as expected and Jack and SuperCollider start and it makes sound. Does anyone have any ideas on how I can adjust my script to get it to run from the button? Adding nohup to sclang does not change anything.

Thanks,  
Carl

---

<div class="post-metadata">

**Author:** ![thetechnobear](https://community.blokas.io/user_avatar/community.blokas.io/thetechnobear/32/73_2.png) [@thetechnobear](https://community.blokas.io/u/thetechnobear)\
**Post date:** [September 13, 2017, 1:06pm UTC](https://community.blokas.io/t/modifying-single-click-sh-scripts/151/14 "2017-09-13T13:06:35Z")

</div>

try login (or s )in as root, and run the script as toot, see if it displays any errors  
… my guess would be you have something about sc setup in your pi user profile (eg. patch to sclang)

the other thing you could do, is to make the script (or at least the application starting bit) run as the PI user.
