- Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathcopy-paste-URL.lua
More file actions
Latest commit
53 lines (41 loc) · 1.18 KB
/
Copy pathcopy-paste-URL.lua
File metadata and controls
53 lines (41 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
functiontrim(s)
return (s:gsub("^%s*(%S+)%s*", "%1"))
end
functionopenURL()
subprocess= {
name="subprocess",
args= { "powershell", "-Command", "Get-Clipboard", "-Raw" },
playback_only=false,
capture_stdout=true,
capture_stderr=true
}
mp.osd_message("Getting URL from clipboard...")
r=mp.command_native(subprocess)
--failed getting clipboard data for some reason
ifr.status<0then
mp.osd_message("Failed getting clipboard data!")
print("Error(string): "..r.error_string)
print("Error(stderr): "..r.stderr)
end
url=r.stdout
ifnoturlthen
return
end
--trim whitespace from string
url=trim(url)
ifnoturlthen
mp.osd_message("clipboard empty")
return
end
--immediately resume playback after loading URL
ifmp.get_property_bool("core-idle") then
ifnotmp.get_property_bool("idle-active") then
mp.command("keypress space")
end
end
--try opening url
--will fail if url is not valid
mp.osd_message("Try Opening URL:\n"..url)
mp.commandv("loadfile", url, "replace")
end
mp.add_key_binding("ctrl+v", openURL)