local env = reaper.GetSelectedEnvelope(0) local ai_index = reaper.InsertAutomationItem(env, -1, 0, 5) reaper.ShowConsoleMsg("Automation item index: " .. ai_index)