13.05.2021, 06:07
Hi
Is it possible to use a script to change the active state of another script?
I tried the following code, however it doesn't seem to change the active state / icon in the script list view. (I'm running a Schneider SHAC with the older logic machine firmware which might be the problem)
I successfully run the following the following code which directly interacts with the database to change the status of schedules - is something similar required to activate / deactivate scripts?
Many thanks in advance
Kind Regards
James
Is it possible to use a script to change the active state of another script?
I tried the following code, however it doesn't seem to change the active state / icon in the script list view. (I'm running a Schneider SHAC with the older logic machine firmware which might be the problem)
Code:
-- Change active status of script
function enableScript(scriptname, active)
if active == true then
script.enable('scriptname')
log('Script "' .. scriptname .. '" is active')
else
script.disable('scriptname')
log('Script "' .. scriptname .. '" is disabled')
end
end
I successfully run the following the following code which directly interacts with the database to change the status of schedules - is something similar required to activate / deactivate scripts?
Code:
-- Change active status of schedule
function enableSchedule(schedulername, active)
query = 'SELECT * FROM schedulers'
for _, scheduler in ipairs(db:getall(query)) do
if scheduler.name == schedulername then
if active == true then
db:update('schedulers', { active = 1 }, { id = scheduler.id })
log('Schedule "' .. schedulername .. '" is active')
else
db:update('schedulers', { active = 0 }, { id = scheduler.id })
log('Schedule "' .. schedulername .. '" is disabled')
end
end
end
end
-- Clear old schedules after updating enable state in database with enableSchedule
function updateSchedulers()
local files = io.ls('/tmp')
for _, file in ipairs(files) do
if file:find('lm-scheduler-', 1, true) then
os.remove('/tmp/' .. file)
end
end
end
Many thanks in advance
Kind Regards
James