This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Change Active Status of a Script
#1
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)

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
Reply


Messages In This Thread
Change Active Status of a Script - by jamesng - 13.05.2021, 06:07

Forum Jump: