08-30-2018, 01:06 PM
I have succeeded in coding this Lua script.
It works in conjunction with a bash script which communicates with a ITTT internet activated power socket.
The bash script will run in a terminal if set to be executable and it looks for the presence of a folder in the a certain place within the home folder.
The Bash Script
When the folder is present it sends an internet curl call to activate the socket and so the light. When not present it sends an internet curl call to deactivate the light. The use of the flag variables is so that the script only sends a curl call when the status changes. (to avoid repeated redundant curl calls). There is another folder which is constantly presents which works to trigger the while loop. (bit of clunky programming)
The lua Script
The script is for an action hook, implementation which then writes the folder to the file system and so triggering action of the bash script - running in the background.
I've gone for this clunky way of getting this to work, because I could get a way to make the ITTT curl call directly from the lua script. So perhaps there is a more elegant way of going about this.
Bash Script
lua Script
It works in conjunction with a bash script which communicates with a ITTT internet activated power socket.
The bash script will run in a terminal if set to be executable and it looks for the presence of a folder in the a certain place within the home folder.
The Bash Script
When the folder is present it sends an internet curl call to activate the socket and so the light. When not present it sends an internet curl call to deactivate the light. The use of the flag variables is so that the script only sends a curl call when the status changes. (to avoid repeated redundant curl calls). There is another folder which is constantly presents which works to trigger the while loop. (bit of clunky programming)
The lua Script
The script is for an action hook, implementation which then writes the folder to the file system and so triggering action of the bash script - running in the background.
I've gone for this clunky way of getting this to work, because I could get a way to make the ITTT curl call directly from the lua script. So perhaps there is a more elegant way of going about this.
Bash Script
Code:
while [ -d "[path to folder]/RECORD_LIGHT_ACTIVE" ]
do
if [ -d "[path to folder]/RECORDING" ]
then
REC_FLAG=1
else
REC_FLAG=0
fi
X_FLAG=1
if [[ "$REC_FLAG" = "1" ]] && [[ "$PREV_FLAG" = "1" ]]
then
X_FLAG=0
fi
if [[ "$REC_FLAG" = "0" ]] && [[ "$PREV_FLAG" = "0" ]]
then
X_FLAG=0
fi
if [[ "$X_FLAG" = "1" ]] && [[ "$REC_FLAG" = "1" ]]
then
curl -X POST https://maker.ifttt.com/[path to maker channel]
PREV_FLAG=1
ECHO -e " RECORD LIGHT ON"
fi
if [[ "$X_FLAG" = "1" ]] && [[ "$REC_FLAG" = "0" ]]
then
curl -X POST https://maker.ifttt.com/[path to maker channel
PREV_FLAG=0
ECHO -e " RECORD LIGHT OFF"
fi
done
lua Script
Code:
ardour {
["type"] = "EditorHook",
name = "Record Light Trigger",
author = "Lawalks",
description = [[
Sends an external call for record light.
]]
}
function signals ()
s = LuaSignal.Set()
s:add ({[LuaSignal.RecordStateChanged] = true})
return s
end
function factory ()
return function (signal)
-- print (Session:record_status())
-- print (Session:actively_recording())
if Session:actively_recording (true)
then
os.execute [[mkdir "[path to folder]/RECORDING"]]
-- print ('recording')
else
os.execute [[rmdir "[path to folder]/RECORDING"]]
-- print ('not recording')
end
end
end