Skip to content

Instantly share code, notes, and snippets.

@dupontgu
Last active July 6, 2021 13:44
Show Gist options
  • Save dupontgu/e3ae585406d4ba48164eafd3b7d279ad to your computer and use it in GitHub Desktop.
Save dupontgu/e3ae585406d4ba48164eafd3b7d279ad to your computer and use it in GitHub Desktop.
ReaScript that triggers actions on IFTTT based on when you start and stop recording in Reaper
turnLightOn = "/bin/sh -c \"curl -H 'Connection: close' -i -X POST 'https://maker.ifttt.com/trigger/record_lamp_on/with/key/your_key_here'\"";
turnLightOff = "/bin/sh -c \"curl -H 'Connection: close' -i -X POST 'https://maker.ifttt.com/trigger/record_lamp_off/with/key/your_key_here'\"";
lastState = 0;
function main()
(
currentState = GetPlayState() & 4;
lastState != currentState ? (
command = currentState > 0 ? turnLightOn : turnLightOff;
ExecProcess(#result, command, 0);
lastState = currentState;
);
defer("main();");
);
main();
@HenriqueAPSilva
Copy link

Thanks for the code! (and for the tutorial at https://medium.com/@dupontgu/a-simple-diy-recording-lamp-that-automatically-syncs-with-your-daw-2825ed82c442)

My IFTTT link works and the lamp turns on and off when I access it via browser, but my Reascript doesn't seem to access the web. I tried editing the code to show a pop up when recording starts and ends and that worked fine, so it seems to be a problem with ExecProcess or with curl (?) I'm new to this.

Any ideas on why it is not working? I could use some test code to see if ExecProcess can run something else...

On a side note, I can use Reaper's remote control, so I guess my firewall is not blocking Reaper.

@dupontgu
Copy link
Author

Not sure how to reply - hopefully you see this @HenriqueAPSilva

You're definitely testing the right things, but it's hard for me to tell where it's going wrong (especially since I'm not an expert with ReaScript). What OS are you using? The first thing I'd recommend is to figure out if the curl command is working outside of Reaper. On Mac/Linux, this is as simple as opening a terminal window, pasting the curl command (with your url inserted), and hitting enter.

Should look like this:
curl -H 'Connection: close' -i -X POST 'https://maker.ifttt.com/trigger/record_lamp_on/with/key/your_key_here'

Let me know if you can get that to work, then maybe I can help figure out the Reaper side.

@HenriqueAPSilva
Copy link

HenriqueAPSilva commented Aug 20, 2020

Not sure how to reply - hopefully you see this @HenriqueAPSilva

You're definitely testing the right things, but it's hard for me to tell where it's going wrong (especially since I'm not an expert with ReaScript). What OS are you using? The first thing I'd recommend is to figure out if the curl command is working outside of Reaper. On Mac/Linux, this is as simple as opening a terminal window, pasting the curl command (with your url inserted), and hitting enter.

Should look like this:
curl -H 'Connection: close' -i -X POST 'https://maker.ifttt.com/trigger/record_lamp_on/with/key/your_key_here'

Let me know if you can get that to work, then maybe I can help figure out the Reaper side.

Tried running curl straight on Windows console and got this error: "curl: (1) Protocol "'https" not supported or disabled in libcurl". I found out that the code can't use sigle quotes, and that the first part is not necessary. So this is the code working on Windows 10:

turnLightOn = "curl -H \"Connection: close\" -i -X POST \"https://maker.ifttt.com/trigger/record_lamp_on/with/key/xxxxxxxxx\"";
turnLightOff = "curl -H \"Connection: close\" -i -X POST \"https://maker.ifttt.com/trigger/record_lamp_off/with/key/xxxxxxxxxx\"";

lastState = 0;
function main()
(
  currentState = GetPlayState() & 4;
  lastState != currentState ? (
    command = currentState > 0 ? turnLightOn : turnLightOff;
    ExecProcess(#result, command, 0);
    lastState = currentState;
  );
  defer("main();");
);

main();

Working fine now! Thanks!

@HenriqueAPSilva
Copy link

Additionally, I would recommend setting this action as a "Global Startup Action" on SWS Extensions

@Lowice
Copy link

Lowice commented Jul 6, 2021

Hi can anybody help me >? im new at this ,.
I have red te above posts but I still can't get it to work in Logic Pro X on my Mac with Big sur osx

i made a connection that worked to turn the ligt on and of ,. but the code gives a syntax error .. here it is :

Creating a new MIDI engine with script

Evaluating MIDI-processing script...
Script failed to evaluate:
[JS Exception] SyntaxError: Unexpected token '('. Expected an opening '{' at the start of a function body. line:17

--- but when I change the expected symbols than is goes until Exeprocess and there I can't get any further .

Can anyone please help me ?

Thnx In advance !

@dupontgu
Copy link
Author

dupontgu commented Jul 6, 2021

@Lowice Sorry, this is not meant to work with Logic! Reaper only.
I do have a tutorial for Pro Tools here, if that helps at all: https://www.youtube.com/watch?v=q4VlN0nZlpw

I can look into Logic if I get a chance, but I don't think you'll be able to use the MIDI script engine.

@Lowice
Copy link

Lowice commented Jul 6, 2021

Oke , well there is an js script editor in logic ,. so I thought is would be possible , I hope that maybe you can help me out ! ,. thank anyway for your reply !
Greetz !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment