Building upon the methods explored here, I’ve been experimenting with using node-red’s Twitter node to interface directly with ruby files in Sonic Pi by means of shell scripting. By creating multiple instances of the Twitter nodes in a single flow, I can set unique search terms, strings, hash tags, etc per node, which correspond to individual ruby files. These files are then called up in Sonic
Pi, via the command line interface sonic-pi-cli. Using AppleScript syntax within a .sh file, we have the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#! /usr/bin/env osascript tell application "System Events" if "Terminal" is not in name of processes then launch application "Terminal" tell process "Terminal" set frontmost to true if (count windows) is 1 then keystroke "n" using command down if (count windows) is 2 then end if end tell end tell tell application "Terminal" do script "`sonic_pi \"run_file '~/Dropbox/Code/Ruby/SonicPi/multiRandom.rb'\"`" in window 1 end tell |
Instead of connecting Twitter nodes to OSC nodes (to communicate with QLab), I am using exec nodes to run the shell scripts. When configuring the exec nodes, the Command is ‘exec’, uncheck the option to ‘append msg.payload’, and in the ‘extra input parameters’ enter the file pathway to your .sh file, including the extension. Make sure your .sh files are executable once you create them. And, obviously, you will need to set the file pathway to a location pertinent to your machine.
The json file of the Node-RED flow is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
[ { "id": "68689119.e0bbb8", "type": "tab", "label": "Flow 2", "disabled": false, "info": "" }, { "id": "fad8a911.f12618", "type": "comment", "z": "68689119.e0bbb8", "name": "README - Runner shell file formatting", "info": "#!/usr/bin/env osascript\n\ntell application \"System Events\" \n if \"Terminal\" is not in name of processes then launch application \"Terminal\" \n tell process \"Terminal\" \n set frontmost to true \n if (count windows) is 1 then keystroke \"n\" using command down \n if (count windows) is 2 then \n end if \n end tell \nend tell\n\ntell application \"Terminal\" \n do script \"`sonic_pi \\\"run_file '~/Dropbox/Code/Ruby/SonicPi/multiRandom.rb'\\\"`\" in window 1\nend tell", "x": 170, "y": 680, "wires": [], "icon": "node-red/alert.png" }, { "id": "5851ef74.e5d77", "type": "exec", "z": "68689119.e0bbb8", "command": "exec", "addpay": false, "append": "/Users/HoganSound/Dropbox/Code/Ruby/SonicPi/Launchers/runner.sh", "useSpawn": "false", "timer": "", "oldrc": false, "name": "runner.sh", "x": 700, "y": 40, "wires": [ [ "2f2edc04.2e97c4" ], [ "2f2edc04.2e97c4" ], [] ] }, { "id": "d5dc63ed.bc90d", "type": "twitter in", "z": "68689119.e0bbb8", "twitter": "", "tags": "", "user": "false", "name": "Twitter watcher", "topic": "tweets", "inputs": 1, "x": 100, "y": 180, "wires": [ [ "5851ef74.e5d77", "2f2edc04.2e97c4" ] ], "outputLabels": [ "trigger" ] }, { "id": "86176a2d.e35d8", "type": "comment", "z": "68689119.e0bbb8", "name": "Sh launcher", "info": "", "x": 710, "y": 80, "wires": [] }, { "id": "a6ae1f1c.89795", "type": "comment", "z": "68689119.e0bbb8", "name": "Enter search terms", "info": "", "x": 110, "y": 240, "wires": [] }, { "id": "79ab5e06.8960f8", "type": "comment", "z": "68689119.e0bbb8", "name": "Duplicate the Twitter - exec node series above for additional search terms and shell script launchers", "info": "", "x": 360, "y": 540, "wires": [] }, { "id": "2f2edc04.2e97c4", "type": "debug", "z": "68689119.e0bbb8", "name": "CONSOLE", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "x": 990, "y": 140, "wires": [] }, { "id": "b294a92b.b6ce7", "type": "comment", "z": "68689119.e0bbb8", "name": "README - Exec node formatting", "info": "Running .sh files from node-red exec node:\nCommand = 'exec'\nadditional info = /path/to/your/fileAndExtension\nOutput = when the command is complete - exec mode", "x": 150, "y": 640, "wires": [], "icon": "node-red/alert.png" }, { "id": "ca23c478.12907", "type": "exec", "z": "68689119.e0bbb8", "command": "exec", "addpay": false, "append": "/Users/HoganSound/Dropbox/Code/Ruby/SonicPi/Launchers/stopper.sh", "useSpawn": "false", "timer": "", "oldrc": false, "name": "stopper.sh", "x": 710, "y": 260, "wires": [ [ "2f2edc04.2e97c4" ], [ "2f2edc04.2e97c4" ], [] ] }, { "id": "97adfb95.66f6a", "type": "inject", "z": "68689119.e0bbb8", "name": "", "topic": "", "payload": "", "payloadType": "date", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 100, "y": 440, "wires": [ [ "ca23c478.12907" ] ] }, { "id": "8ed5f43d.cb004", "type": "inject", "z": "68689119.e0bbb8", "name": "", "topic": "", "payload": "", "payloadType": "date", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 100, "y": 40, "wires": [ [ "5851ef74.e5d77" ] ] }, { "id": "891ccced.59c548", "type": "comment", "z": "68689119.e0bbb8", "name": "Manual stop", "info": "", "x": 90, "y": 480, "wires": [] }, { "id": "9dfacc49.732b5", "type": "comment", "z": "68689119.e0bbb8", "name": "Manual start", "info": "", "x": 90, "y": 80, "wires": [] }, { "id": "3054b841.f3e56", "type": "comment", "z": "68689119.e0bbb8", "name": "Valid terms will trigger shell script and print to debug console", "info": "", "x": 240, "y": 280, "wires": [] }, { "id": "4b60587e.3bed28", "type": "comment", "z": "68689119.e0bbb8", "name": "README - Stopper shell file formatting", "info": "#! /usr/bin/env osascript\n\ntell application \"System Events\"\n\tif \"Terminal\" is not in name of processes then launch application \"Terminal\"\n\ttell process \"Terminal\"\n\t\tset frontmost to true\n\t\tif (count windows) is 1 then keystroke \"n\" using command down\n\t\tif (count windows) is 2 then\n\t\tend if\n\tend tell\n\t\nend tell\n\ntell application \"Terminal\"\n\tdo script \"`sonic_pi \\\"stop\\\"`\" in window 1\nend tell", "x": 170, "y": 720, "wires": [], "icon": "node-red/alert.png" }, { "id": "34460a5f.27c886", "type": "comment", "z": "68689119.e0bbb8", "name": "Stop playback", "info": "", "x": 710, "y": 300, "wires": [] } ] |
1 |
|
And the stopper shell is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#! /usr/bin/env osascript # AppleScript # halt playback tell application "System Events" if "Terminal" is not in name of processes then launch application "Terminal" tell process "Terminal" set frontmost to true if (count windows) is 1 then keystroke "n" using command down if (count windows) is 2 then end if end tell end tell tell application "Terminal" do script "`sonic_pi \"stop\"`" in window 1 end tell |
The whole thing should look like this:

This method uses only freely available tools, rather than paid commercial software – which is not to say you shouldn’t use QLab if you want, but Script cues are a paid feature.