Created
March 17, 2018 16:50
-
-
Save TheAMM/712bbed3c7b5f00ff961714378ffaaa6 to your computer and use it in GitHub Desktop.
Lua script for mpv to write lines to a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you <3