Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mp = require 'mp'
- local utils = require 'mp.utils'
- function detect_platform()
- local o = {}
- -- Kind of a dumb way of detecting the platform but whatever
- if mp.get_property_native('options/vo-mmcss-profile', o) ~= o then
- return 'windows'
- elseif mp.get_property_native('options/input-app-events', o) ~= o then
- return 'macos'
- end
- return 'linux'
- end
- function trim(s)
- return s:match"^%s*(.-)%s*$" or s
- end
- local platform = detect_platform()
- clipboard_module = {}
- function clipboard_module.set_clipboard(content)
- content = '"' .. content .. '"' -- let os handle the quotes
- if platform == 'linux' then
- os.execute('echo ' .. content .. ' | xclip -selection c')
- elseif platform == 'windows' then
- os.execute('powershell -NoProfile -Command Set-Clipboard' .. content)
- elseif platform == 'macos' then
- os.execute('echo ' .. content .. ' | pbcopy')
- end
- end
- function clipboard_module.get_clipboard()
- local handle = nil
- if platform == 'linux' then
- handle = io.popen('xclip -selection c -o')
- elseif platform == 'windows' then
- local handle = io.popen('powershell -NoProfile -Command Get-Clipboard')
- elseif platform == 'macos' then
- handle = io.popen('pbpaste')
- end
- if not handle then
- return nil
- end
- local result = handle:read("*all")
- return trim(result)
- end
- return clipboard_module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement