Skip to content

Instantly share code, notes, and snippets.

@TheAMM
Created March 17, 2018 16:50
Show Gist options
  • Save TheAMM/712bbed3c7b5f00ff961714378ffaaa6 to your computer and use it in GitHub Desktop.
Save TheAMM/712bbed3c7b5f00ff961714378ffaaa6 to your computer and use it in GitHub Desktop.
Lua script for mpv to write lines to a file
local assdraw = require 'mp.assdraw'
local msg = require 'mp.msg'
local opt = require 'mp.options'
local utils = require 'mp.utils'
--[[
Simple script to expose a command to write a line to a file.
Example bind:
v script-message write-to-file "/tmp/some_file" "Now playing: ${path} at ${playback-position}"
]]--
local SCRIPT_COMMAND_NAME = 'write-to-file'
function script_command_handler(filename, input_string)
local file_object = io.open(filename, 'a')
if file_object == nil then
msg.error('Unable to open file for appending: ' .. filename)
return
end
file_object:write(input_string .. '\n')
file_object:close()
end
mp.register_script_message(SCRIPT_COMMAND_NAME, script_command_handler)
@lord-carlos
Copy link

Thank you <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment