-
-
Save Sneakpeakcss/05a97d509b8be67a6f11400b0bee54ab to your computer and use it in GitHub Desktop.
-- open-in-explorer.lua | |
mp.add_key_binding(nil, "open-in-explorer", function() | |
local path = mp.get_property("path") | |
if path ~= nil and not path:match("^%a[%a%d-_]+://") then | |
path = string.gsub(path, "/", "\\") | |
mp.command_native({ | |
name = "subprocess", | |
playback_only = false, | |
args = { 'explorer', '/select,', path .. ' ' }, | |
}) | |
else | |
mp.osd_message("Invalid path: " .. (path or "No path provided")) | |
end | |
end) |
uosc has a cross-platform solution with its show-in-directory
script binding.
uosc has a cross-platform solution with its
show-in-directory
script binding.
Well, now that's slightly amusing. This whole thing came to be because of an issue with PowerShell version in mpv.net
, but for some reason it didn't hit me to check if uosc didn't already have this. I guess this is still useful as a standalone solution for people that don't use uosc.
Though going through my weirdly named test files, uosc
has an issue with paths that have a comma in them:
C:\test\test2\aa,aa.mp4
this will open "This PC" directory
C:\test\test2\,aaaa.mp4
this will open "test" directory and select test2 folder
Everything starts working fine the moment there's a space anywhere in the path.
[edit]
Wait… This one also has the same issue, i'm quite sure that i've used the same files testing this thing previously, but apparently not? PowerShell version also is broken in those 2 cases.
C:\test\test2\..,aaaa.mp4
uh huh… Amazing way of navigating directories
Here's the problem in more detail: mpvnet-player/mpv.net#580 (comment)
(...)
This seems to work:mp.add_key_binding(nil, "open-in-explorer", function() local path = mp.get_property("path") if path ~= nil and not path:match("^%a[%a%d-_]+://") then local ps_code = [[ Start-Process -FilePath explorer.exe -ArgumentList "/select,`"__path__`"" ]] local path = string.gsub(path, "/", "\\") local path = string.gsub(path, "[%(%)%.%+%-%*%?%[%]%^%$%%]", "%%%1") local ps_path = string.gsub(path, "([$`])", "`%1") -- escape dollar/backtick signs for PowerShell local ps_code = string.gsub(ps_code, "__path__", ps_path) mp.command_native({ name = "subprocess", playback_only = false, args = { 'powershell', '-NoProfile', '-Command', ps_code }, }) else mp.osd_message("Invalid path: " .. (path or "No path provided")) end end)We're breaking records… At this point this seems like a case of "just Windows / mpv things" and pick your poison. It would be far more preferable to get mpv to pass it with a single set of double quotes through cmd in all cases, but i don't think it's possible.
Okay, main version seems to now work in every single case, so there's again no need to use the above PowerShell solution.
Was the fix just appending a space to the path? Please submit a PR with uosc since you have a setup to reproduce this. 🙏
Yea, a trailing space was all it takes to fix this. I've submited the mentioned PR.
input.conf
Here's a rudimentary PowerShell version, mostly for reference if someone wants to tinker with adding some additional actions through it:
Otherwise, for its original purpose it's preferable to use the main version since it's faster than PS: