Skip to content

Instantly share code, notes, and snippets.

@DDRBoxman
Created August 21, 2018 03:39
Show Gist options
  • Save DDRBoxman/7d620b8d84ad425a912cf6e7b86c13c7 to your computer and use it in GitHub Desktop.
Save DDRBoxman/7d620b8d84ad425a912cf6e7b86c13c7 to your computer and use it in GitHub Desktop.
obs = obslua
source_name = ""
last_text = ""
time_format = ""
function set_time_text()
text = os.date(time_format)
if text ~= last_text then
local source = obs.obs_get_source_by_name(source_name)
if source ~= nil then
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
last_text = text
end
function timer_callback()
set_time_text()
end
----------------------------------------------------------
function script_properties()
local props = obs.obs_properties_create()
local p = obs.obs_properties_add_list(props, "source", "Text Source", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING)
local sources = obs.obs_enum_sources()
if sources ~= nil then
for _, source in ipairs(sources) do
source_id = obs.obs_source_get_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(p, name, name)
end
end
end
obs.source_list_release(sources)
obs.obs_properties_add_text(props, "time_format", "Time Format", obs.OBS_TEXT_DEFAULT)
return props
end
function script_description()
return "Sets a text source to show the current time"
end
function script_update(settings)
source_name = obs.obs_data_get_string(settings, "source")
time_format = obs.obs_data_get_string(settings, "time_format")
end
function script_defaults(settings)
obs.obs_data_set_default_string(settings, "time_format", "%A, %B %d %Y at %I:%M:%S %p")
end
function script_save(settings)
end
function script_load(settings)
obs.timer_add(timer_callback, 1000)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment