Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.38 KB | None | 0 0
  1. local mp = require 'mp'
  2. local utils = require 'mp.utils'
  3.  
  4. function detect_platform()
  5.     local o = {}
  6.     -- Kind of a dumb way of detecting the platform but whatever
  7.     if mp.get_property_native('options/vo-mmcss-profile', o) ~= o then
  8.         return 'windows'
  9.     elseif mp.get_property_native('options/input-app-events', o) ~= o then
  10.         return 'macos'
  11.     end
  12.     return 'linux'
  13. end
  14.  
  15.  
  16. function trim(s)
  17.     return s:match"^%s*(.-)%s*$" or s
  18. end
  19.  
  20. local platform = detect_platform()
  21.  
  22. clipboard_module = {}
  23.  
  24. function clipboard_module.set_clipboard(content)
  25.     content = '"' .. content .. '"' -- let os handle the quotes
  26.     if platform == 'linux' then
  27.         os.execute('echo ' .. content .. ' | xclip -selection c')
  28.     elseif platform == 'windows' then
  29.         os.execute('powershell -NoProfile -Command Set-Clipboard' .. content)
  30.     elseif platform == 'macos' then
  31.         os.execute('echo ' .. content .. ' | pbcopy')
  32.     end
  33. end
  34.  
  35. function clipboard_module.get_clipboard()
  36.     local handle = nil
  37.     if platform == 'linux' then
  38.         handle = io.popen('xclip -selection c -o')
  39.     elseif platform == 'windows' then
  40.         local handle = io.popen('powershell -NoProfile -Command Get-Clipboard')
  41.         elseif platform == 'macos' then
  42.         handle = io.popen('pbpaste')
  43.     end
  44.  
  45.     if not handle then
  46.         return nil
  47.     end
  48.  
  49.     local result = handle:read("*all")
  50.     return trim(result)
  51. end
  52.  
  53. return clipboard_module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement