obs = obslua -- Structure to store settings for each text source source_settings = { {name = "", show_time = true, show_am_pm = true, show_weekday = false, show_calendar_week = false, show_date = false}, {name = "", show_time = true, show_am_pm = true, show_weekday = false, show_calendar_week = false, show_date = false}, {name = "", show_time = true, show_am_pm = true, show_weekday = false, show_calendar_week = false, show_date = false}, {name = "", show_time = true, show_am_pm = true, show_weekday = false, show_calendar_week = false, show_date = false}, {name = "", show_time = true, show_am_pm = true, show_weekday = false, show_calendar_week = false, show_date = false} } -- Set the locale to English os.setlocale("en_US.UTF-8") -- Variable to track the last update time last_update_time = 0 function script_description() return "Allows updating up to five text sources with individual settings for time, AM/PM, date, weekday, and calendar week every 30 seconds." end function script_update(settings) for i = 1, 5 do source_settings[i].name = obs.obs_data_get_string(settings, "source" .. i) source_settings[i].show_time = obs.obs_data_get_bool(settings, "show_time" .. i) source_settings[i].show_am_pm = obs.obs_data_get_bool(settings, "show_am_pm" .. i) source_settings[i].show_weekday = obs.obs_data_get_bool(settings, "show_weekday" .. i) source_settings[i].show_calendar_week = obs.obs_data_get_bool(settings, "show_calendar_week" .. i) source_settings[i].show_date = obs.obs_data_get_bool(settings, "show_date" .. i) end end function script_properties() local props = obs.obs_properties_create() for i = 1, 5 do local p = obs.obs_properties_add_list(props, "source" .. i, "Source " .. i, obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING) add_sources(p) obs.obs_properties_add_bool(props, "show_time" .. i, "Show time") obs.obs_properties_add_bool(props, "show_am_pm" .. i, "Show AM/PM") obs.obs_properties_add_bool(props, "show_date" .. i, "Show date") obs.obs_properties_add_bool(props, "show_weekday" .. i, "Show weekday") obs.obs_properties_add_bool(props, "show_calendar_week" .. i, "Show calendar week") end return props end function add_sources(property) local sources = obs.obs_enum_sources() if sources ~= nil then for _, source in ipairs(sources) do local source_id = obs.obs_source_get_unversioned_id(source) if source_id == "text_gdiplus" or source_id == "text_ft2_source" then local name = obs.obs_source_get_name(source) obs.obs_property_list_add_string(property, name, name) end end end obs.source_list_release(sources) end function script_tick(seconds) local current_time = os.time() if current_time - last_update_time >= 50 then for i, setting in ipairs(source_settings) do update_source(setting.name, setting.show_time, setting.show_am_pm, setting.show_weekday, setting.show_calendar_week, setting.show_date) end last_update_time = current_time end end function update_source(source_name, show_time, show_am_pm, show_weekday, show_calendar_week, show_date) local source = obs.obs_get_source_by_name(source_name) if source ~= nil then local time_format = "%I:%M" local date_format = "%m/%d/%Y" local weekday_format = "%a" local calendar_week_format = "%U" local text = "" if show_time then text = os.date(time_format) if show_am_pm then text = text .. " " .. os.date("%p") end end if show_date then local date = os.date(date_format) text = date .. " " .. text end if show_weekday then local weekday = os.date(weekday_format) text = weekday .. " " .. text end if show_calendar_week then local calendar_week = os.date(calendar_week_format) text = "CW " .. calendar_week .. " " .. text end local settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", text) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source) end end