-- Delete the last recording in recordings folder, stop and delete, and stop and delete + rerecord -- Author: Johan Reyes (jrey2125@gmail.com) -- Version 1.1 obs = obslua hotkey_id = obs.OBS_INVALID_HOTKEY_ID hotkey_id2 = obs.OBS_INVALID_HOTKEY_ID hotkey_id3 = obs.OBS_INVALID_HOTKEY_ID time = 0 -- Adds buttons that correspond to each function function script_properties(settings) local props = obs.obs_properties_create() obs.obs_properties_add_button(props, "delete_last_recording", "Delete Last Recording", delete_last_recording) obs.obs_properties_add_button(props, "stop_recording_then_delete_last_recording", "Stop Recording + Delete Last Recording", stop_recording_and_delete_last_recording) obs.obs_properties_add_button(props, "stop_delete_then_record", "Stop Recording, Delete, Begin Recording", stop_delete_then_record) obs.obs_properties_add_int(props, "time", "Seconds to Wait Before Starting New Recording", 0, 2147483647, 10) return props end function script_description() return "Adds three hotkeys and buttons to delete the last recording in recordings folder, stop recording and then delete the last recording right after, and to do the latter but restart recording after the time variable amount of seconds. \n \n (PERMANENTLY DELETES RECORDING, NOT TO RECYCLING BIN)" end function script_update(settings) time = obs.obs_data_get_int(settings, "time") end function script_defaults(settings) obs.obs_data_set_default_int(settings, "time", 0) end function script_load(settings) hotkey_id = obs.obs_hotkey_register_frontend("delete_last_recording", "Delete Last Recording", delete_last_recording) local hotkey_save_array = obs.obs_data_get_array(settings, "delete_last_recording") obs.obs_hotkey_load(hotkey_id, hotkey_save_array) obs.obs_data_array_release(hotkey_save_array) hotkey_id2 = obs.obs_hotkey_register_frontend("stop_recording_then_delete_last_recording", "Stop Recording + Delete Last Recording", stop_recording_and_delete_last_recording) local hotkey_save_array2 = obs.obs_data_get_array(settings, "stop_recording_then_delete_last_recording") obs.obs_hotkey_load(hotkey_id2, hotkey_save_array2) obs.obs_data_array_release(hotkey_save_array2) hotkey_id3 = obs.obs_hotkey_register_frontend("stop_delete_then_record", "Stop Recording, Delete, Begin Recording", stop_delete_then_record) local hotkey_save_array3 = obs.obs_data_get_array(settings, "stop_delete_then_record") obs.obs_hotkey_load(hotkey_id3, hotkey_save_array3) obs.obs_data_array_release(hotkey_save_array3) time = obs.obs_data_get_int(settings, "time") end function script_save(settings) local hotkey_save_array = obs.obs_hotkey_save(hotkey_id) obs.obs_data_set_array(settings, "delete_last_recording", hotkey_save_array) obs.obs_data_array_release(hotkey_save_array) local hotkey_save_array2 = obs.obs_hotkey_save(hotkey_id2) obs.obs_data_set_array(settings, "stop_recording_then_delete_last_recording", hotkey_save_array2) obs.obs_data_array_release(hotkey_save_array2) local hotkey_save_array3 = obs.obs_hotkey_save(hotkey_id3) obs.obs_data_set_array(settings, "stop_delete_then_record", hotkey_save_array3) obs.obs_data_array_release(hotkey_save_array3) obs.obs_data_set_int(settings, "time", time) end function delete_last_recording() local fileName = obs.obs_frontend_get_last_recording() local result, message = os.remove(fileName) -- if file is removed if result then print("Recording deleted successfully.") else print("Recording deletion failed.", message) end end -- Stops recording, waits 1 second, then deletes function stop_recording_and_delete_last_recording() obs.obs_frontend_recording_stop() sleep(1) delete_last_recording() end function stop_delete_then_record() stop_recording_and_delete_last_recording() sleep(time) obs.obs_frontend_recording_start() end --waits x amount of sec function sleep(a) local sec = tonumber(os.clock() + a) while (os.clock() < sec) do end end