├── README.md └── open-file-dialog.lua /README.md: -------------------------------------------------------------------------------- 1 | open-file-dialog.lua 2 | ==================== 3 | 4 | **open-file-dialog.lua** is a script for mpv that can launch a regular Windows 5 | file open dialog from a key binding (default: Ctrl+O.) 6 | 7 | ![screenshot](https://rossy.github.io/mpv-open-file-dialog/screen.png) 8 | 9 | This script requires PowerShell. It should work on all Windows versions that 10 | mpv supports. Tested in Windows 8.1 and 10. 11 | 12 | ![CC0](https://licensebuttons.net/p/zero/1.0/80x15.png) 13 | -------------------------------------------------------------------------------- /open-file-dialog.lua: -------------------------------------------------------------------------------- 1 | -- To the extent possible under law, the author(s) have dedicated all copyright 2 | -- and related and neighboring rights to this software to the public domain 3 | -- worldwide. This software is distributed without any warranty. See 4 | -- for a copy of the CC0 5 | -- Public Domain Dedication, which applies to this software. 6 | 7 | utils = require 'mp.utils' 8 | 9 | function open_file_dialog() 10 | local was_ontop = mp.get_property_native("ontop") 11 | if was_ontop then mp.set_property_native("ontop", false) end 12 | local res = utils.subprocess({ 13 | args = {'powershell', '-NoProfile', '-Command', [[& { 14 | Trap { 15 | Write-Error -ErrorRecord $_ 16 | Exit 1 17 | } 18 | Add-Type -AssemblyName PresentationFramework 19 | 20 | $u8 = [System.Text.Encoding]::UTF8 21 | $out = [Console]::OpenStandardOutput() 22 | 23 | $ofd = New-Object -TypeName Microsoft.Win32.OpenFileDialog 24 | $ofd.Multiselect = $true 25 | 26 | If ($ofd.ShowDialog() -eq $true) { 27 | ForEach ($filename in $ofd.FileNames) { 28 | $u8filename = $u8.GetBytes("$filename`n") 29 | $out.Write($u8filename, 0, $u8filename.Length) 30 | } 31 | } 32 | }]]}, 33 | cancellable = false, 34 | }) 35 | if was_ontop then mp.set_property_native("ontop", true) end 36 | if (res.status ~= 0) then return end 37 | 38 | local first_file = true 39 | for filename in string.gmatch(res.stdout, '[^\n]+') do 40 | mp.commandv('loadfile', filename, first_file and 'replace' or 'append') 41 | first_file = false 42 | end 43 | end 44 | 45 | mp.add_key_binding('ctrl+o', 'open-file-dialog', open_file_dialog) 46 | --------------------------------------------------------------------------------