--[[ OBS Studio datetime scriptThis script transforms a text source into a digital clock. The datetime formatis configurable and uses the same syntax than the Lua os.date() call.]]obs=obsluasource_name=""datetime_format=""activated=false-- Function to set the time textfunctionset_datetime_text(source,format)localtext=os.date(format)localsettings=obs.obs_data_create()obs.obs_data_set_string(settings,"text",text)obs.obs_source_update(source,settings)obs.obs_data_release(settings)endfunctiontimer_callback()localsource=obs.obs_get_source_by_name(source_name)ifsource~=nilthenset_datetime_text(source,datetime_format)obs.obs_source_release(source)endendfunctionactivate(activating)ifactivated==activatingthenreturnendactivated=activatingifactivatingthenobs.timer_add(timer_callback,1000)elseobs.timer_remove(timer_callback)endend-- Called when a source is activated/deactivatedfunctionactivate_signal(cd,activating)localsource=obs.calldata_source(cd,"source")ifsource~=nilthenlocalname=obs.obs_source_get_name(source)if(name==source_name)thenactivate(activating)endendendfunctionsource_activated(cd)activate_signal(cd,true)endfunctionsource_deactivated(cd)activate_signal(cd,false)endfunctionreset()activate(false)localsource=obs.obs_get_source_by_name(source_name)ifsource~=nilthenlocalactive=obs.obs_source_showing(source)obs.obs_source_release(source)activate(active)endend----------------------------------------------------------functionscript_description()return"Sets a text source to act as a clock when the source is active.\\The datetime format can use the following tags:\\ %a abbreviated weekday name (e.g., Wed)\ %A full weekday name (e.g., Wednesday)\ %b abbreviated month name (e.g., Sep)\ %B full month name (e.g., September)\ %c date and time (e.g., 09/16/98 23:48:10)\ %d day of the month (16) [01-31]\ %H hour, using a 24-hour clock (23) [00-23]\ %I hour, using a 12-hour clock (11) [01-12]\ %M minute (48) [00-59]\ %m month (09) [01-12]\ %p either \"am\" or \"pm\" (pm)\ %S second (10) [00-61]\ %w weekday (3) [0-6 = Sunday-Saturday]\ %x date (e.g., 09/16/98)\ %X time (e.g., 23:48:10)\ %Y full year (1998)\ %y two-digit year (98) [00-99]\ %% the character `%´"endfunctionscript_properties()localprops=obs.obs_properties_create()obs.obs_properties_add_text(props,"format","Datetime format",obs.OBS_TEXT_DEFAULT)localp=obs.obs_properties_add_list(props,"source","Text Source",obs.OBS_COMBO_TYPE_EDITABLE,obs.OBS_COMBO_FORMAT_STRING)localsources=obs.obs_enum_sources()ifsources~=nilthenfor_,sourceinipairs(sources)dosource_id=obs.obs_source_get_id(source)ifsource_id=="text_gdiplus"orsource_id=="text_ft2_source"thenlocalname=obs.obs_source_get_name(source)obs.obs_property_list_add_string(p,name,name)endendendobs.source_list_release(sources)returnpropsendfunctionscript_defaults(settings)obs.obs_data_set_default_string(settings,"format","%X")endfunctionscript_update(settings)activate(false)source_name=obs.obs_data_get_string(settings,"source")datetime_format=obs.obs_data_get_string(settings,"format")reset()endfunctionscript_load(settings)localsh=obs.obs_get_signal_handler()obs.signal_handler_connect(sh,"source_show",source_activated)obs.signal_handler_connect(sh,"source_hide",source_deactivated)end