obs = obslua
local enabled = true
local last_recording_path = ""
function script_description()
return "Prompts to rename your recording immediately after stopping (Windows)."
end
function script_properties()
local props = obs.obs_properties_create()
obs.obs_properties_add_bool(props, "enabled", "Prompt to rename on Recording Stop")
return props
end
function script_defaults(settings)
obs.obs_data_set_default_bool(settings, "enabled", true)
end
function script_update(settings)
enabled = obs.obs_data_get_bool(settings, "enabled")
end
function prompt_and_rename()
obs.timer_remove(prompt_and_rename)
if last_recording_path == nil or last_recording_path == "" then
return
end
-- Extract directory, base filename, and extension (.mkv / .mp4)
local dir, filename, ext = string.match(last_recording_path, "(.-)([^\\/]-)(%.[^%.\\/]+)$")
if not dir or not filename or not ext then
return
end
-- Escape single quotes for PowerShell
local safe_filename = string.gsub(filename, "'", "''")
-- Launch Windows InputBox via PowerShell
local ps_cmd = string.format(
[[powershell -NoProfile -WindowStyle Hidden -Command "Add-Type -AssemblyName Microsoft.VisualBasic; $res = [Microsoft.VisualBasic.Interaction]::InputBox('Enter new recording name (Cancel to keep original):', 'Record Rename', '%s'); Write-Output $res"]],
safe_filename
)
local handle = io.popen(ps_cmd)
if not handle then return end
local new_name = handle:read("*a")
handle:close()
-- Trim whitespace/newlines
new_name = string.gsub(new_name or "", "^%s*(.-)%s*$", "%1")
-- Remove characters forbidden in Windows filenames
new_name = string.gsub(new_name, '[\\/:*?"<>|]', "")
if new_name ~= "" and new_name ~= filename then
local new_path = dir .. new_name .. ext
local ok, err = os.rename(last_recording_path, new_path)
if ok then
obs.script_log(obs.LOG_INFO, "Renamed recording to: " .. new_name .. ext)
else
obs.script_log(obs.LOG_WARNING, "Failed to rename recording: " .. tostring(err))
end
end
end
function on_event(event)
if event == obs.OBS_FRONTEND_EVENT_RECORDING_STOPPED and enabled then
last_recording_path = obs.obs_frontend_get_last_recording()
-- Wait 300ms to ensure OBS finishes closing the file handle
obs.timer_add(prompt_and_rename, 300)
end
end
function script_load(settings)
obs.obs_frontend_add_event_callback(on_event)
end