Last active
August 9, 2020 09:59
-
-
Save Reyuu/2069741ba5ff8329bbd121d5d240a817 to your computer and use it in GitHub Desktop.
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
-- Copies currently displayed subtitles to clipboard automatically. | |
-- Use CTRL+B to enable or disable. | |
-- Default behaviour is disabled on start. | |
utils = require 'mp.utils' | |
automatic_copy = false | |
last_value = "" | |
function bool_to_number(value) | |
return value and 1 or 0 | |
end | |
local function set_clipboard(value) | |
local res = utils.subprocess({ args = { | |
'powershell', '-NoProfile', '-Command', string.format([[& { | |
Trap { | |
Write-Error -ErrorRecord $_ | |
Exit 1 | |
} | |
Add-Type -AssemblyName PresentationCore | |
[System.Windows.Clipboard]::SetText('%s') | |
}]], value) | |
} }) | |
end | |
function copy_to_clipboard(name, value) | |
if automatic_copy then | |
if (value ~= last_value) and (value ~= "") then | |
set_clipboard(value) | |
last_value = value | |
end | |
end | |
end | |
function toggle_clipboard() | |
-- lua is shit | |
if automatic_copy then | |
automatic_copy = false | |
mp.osd_message("◦ Autocopy disabled") | |
else | |
automatic_copy = true | |
mp.osd_message("• Autocopy enabled") | |
end | |
end | |
mp.observe_property("sub-text", "string", copy_to_clipboard) | |
mp.add_key_binding("ctrl+b", toggle_clipboard) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment