# Headless Sonic Pi on Raspberry Pi

**URL:** <https://in-thread.sonic-pi.net/t/headless-sonic-pi-on-raspberry-pi/5655>\
**Category:** \[P\] Patreon Support\
**Created:** [May 31, 2021, 12:19am UTC](https://in-thread.sonic-pi.net/t/headless-sonic-pi-on-raspberry-pi/5655 "2021-05-31T00:19:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![droussel](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/droussel/32/2008_2.png) [@droussel](https://in-thread.sonic-pi.net/u/droussel)\
**Post date:** [May 31, 2021, 12:19am UTC](https://in-thread.sonic-pi.net/t/headless-sonic-pi-on-raspberry-pi/5655/1 "2021-05-31T00:19:23Z")

</div>

Hi, I haven’t found much recent information on this on the forum but sorry if I’m missing something obvious.

Is there a way once to launch a script on a headless SonicPi instance? I’m basically looking for a command line version of sonic pi that can take a config file or some command line arguments to pass it the script to load, etc.

I have a Blokas PiSound which I would like to use to run SonicPi script along with some custom midi controllers. Is that possible?

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [May 31, 2021, 2:18am UTC](https://in-thread.sonic-pi.net/t/headless-sonic-pi-on-raspberry-pi/5655/2 "2021-05-31T02:18:37Z")

</div>

Hello @droussel,

There is no built-in command line access.  
Several people have created external tools which allow you to communicate directly with the Sonic Pi server from the command line.  
Some options:

> **[Widdershin/sonic-pi-cli](https://github.com/Widdershin/sonic-pi-cli)**
>
> A simple command line interface for Sonic Pi, written in Ruby

> **[emlyn/sonic-pi-tool](https://github.com/emlyn/sonic-pi-tool)**
>
> 🎻 Controlling Sonic Pi from the command line, in Python.

(These also may have been ported to/designed with other languages, just have a search on your favourite search engine).  
_Note_: these may or may not be up to date with a change made in Sonic Pi a little while ago, regarding the way the server listened for network messages.

Alternatively, if you’re just after a way to automatically load and run a particular script on Sonic Pi startup, and you don’t mind running the GUI, you can add your code to `~/.sonic-pi/config/init.rb`. (or run an external file via `run_file` from there too for example).

---

<div class="post-metadata">

**Author:** ![droussel](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/droussel/32/2008_2.png) [@droussel](https://in-thread.sonic-pi.net/u/droussel)\
**Post date:** [May 31, 2021, 2:26am UTC](https://in-thread.sonic-pi.net/t/headless-sonic-pi-on-raspberry-pi/5655/3 "2021-05-31T02:26:08Z")

</div>

Thanks @ethancrawford!

Ok, so it means I need to have an x server running for SPi to work. I’ll look into how the sonic-pi-tool though, it may be what I need.

Thanks!

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [May 31, 2021, 2:27am UTC](https://in-thread.sonic-pi.net/t/headless-sonic-pi-on-raspberry-pi/5655/4 "2021-05-31T02:27:21Z")

</div>

Np. As noted on discord, the third party tools are all command line based, it’s only the `init.rb` approach that needs a GUI.

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [May 31, 2021, 11:03am UTC](https://in-thread.sonic-pi.net/t/headless-sonic-pi-on-raspberry-pi/5655/5 "2021-05-31T11:03:47Z")

</div>

I have used [this technique](https://in-thread.sonic-pi.net/t/sonic-pi-for-standalone-installations/225/4) to run Sonic Pi headless. However it is not compatible with using VNCserver on the same Pi.  
However with the latest OS, I boot (for example on a Pi400) with VNCserver enabled, but no monitor attached, and then I can either attach with a vnc client from my mac, or I send signals to SP via the [cli gem](https://github.com/Widdershin/sonic-pi-cli) as Ethan suggests. Note you can set SP to boot automatically by copying the desktop file to the autostart folder  
` cp usr/share/applications/sonic-pi.desktop ~/.config/autostart`  
Once you have SP running with your PiSound board, you can use the sonic-pi-cli to send a file of commands to sonic pi using `sonic_pi "run_file '/path/to/filename'"` The cli has to be running on the same pi, but it is possible to call it from a remote machine using a python script.  
4 years ago I did [quite a large project](https://www.youtube.com/watch?v=G8DOquunrFc) involving 2 PiSound boards and an iPad or iPhone running TouchOSC which shows what can be done headless. (the code probably needs slight tweaking to suit the latest OSC protocols in SP 3.3.1)
