Skip to content

Commit d492f04

Browse files
feat(open-dialog): add PowerShell version
1 parent 46de1e8 commit d492f04

File tree

4 files changed

+106
-13
lines changed

4 files changed

+106
-13
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [ ] `misc.lua`
77
* [ ] `open-dialog/kdialog.lua`
88
* [ ] `open-dialog/zenity.lua`
9+
* [ ] `open-dialog/powershell.lua`
910

1011
## Description
1112
<!--- Provide a detailed description of the issue. -->
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
steps:
1111
- name: Add to Clipshot project
1212
if: |
13-
contains(github.event.issue.body, '[x] `clipshot.lua`)'
13+
contains(github.event.issue.body, '[x] `clipshot.lua`')
1414
uses: alex-page/[email protected]
1515
with:
1616
project: Clipshot
@@ -19,7 +19,7 @@ jobs:
1919

2020
- name: Add to Misc project
2121
if: |
22-
contains(github.event.issue.body, '[x] `misc.lua`)'
22+
contains(github.event.issue.body, '[x] `misc.lua`')
2323
uses: alex-page/[email protected]
2424
with:
2525
project: Misc
@@ -28,7 +28,7 @@ jobs:
2828

2929
- name: Add to Open Dialog (KDialog) project
3030
if: |
31-
contains(github.event.issue.body, '[x] `open-dialog/kdialog.lua`)'
31+
contains(github.event.issue.body, '[x] `open-dialog/kdialog.lua`')
3232
uses: alex-page/[email protected]
3333
with:
3434
project: Open Dialog (KDialog)
@@ -37,9 +37,18 @@ jobs:
3737

3838
- name: Add to Open Dialog (Zenity) project
3939
if: |
40-
contains(github.event.issue.body, '[x] `open-dialog/zenity.lua`)'
40+
contains(github.event.issue.body, '[x] `open-dialog/zenity.lua`')
4141
uses: alex-page/[email protected]
4242
with:
4343
project: Open Dialog (Zenity)
4444
column: To do
4545
repo-token: ${{secrets.GITHUB_TOKEN}}
46+
47+
- name: Add to Open Dialog (PowerShell) project
48+
if: |
49+
contains(github.event.issue.body, '[x] `open-dialog/powershell.lua`')
50+
uses: alex-page/[email protected]
51+
with:
52+
project: Open Dialog (PowerShell)
53+
column: To do
54+
repo-token: ${{secrets.GITHUB_TOKEN}}

open-dialog/README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,20 @@ If not, you should download
3232

3333
[xdotool][xdotool] is required for both scripts.
3434

35+
### Windows
36+
37+
You just have to download [powershell.lua](powershell.lua).
38+
3539
### MacOS
3640

3741
You can install Zenity from [MacPorts][ports]
3842
or [Homebrew][brew] and download [zenity_nox.lua][zenity-nox].
3943

4044
**TODO**: Write an AppleScript version.
4145

42-
### Windows
43-
44-
You can install Zenity from [zenity-windows][windows]
45-
or [WinZenity][winzenity] and download [zenity_nox.lua][zenity-nox].
46-
47-
**TODO**: Write a PowerShell version.
48-
4946
[kdialog]: https://github.com/KDE/kdialog
5047
[zenity]: https://github.com/GNOME/zenity
5148
[xdotool]: https://github.com/jordansissel/xdotool
5249
[zenity-nox]: https://git.io/JeZZL
5350
[brew]: https://formulae.brew.sh/formula/zenity
5451
[ports]: https://ports.macports.org/port/zenity/summary
55-
[windows]: https://github.com/kvaps/zenity-windows
56-
[winzenity]: https://github.com/maravento/winzenity

open-dialog/powershell.lua

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
utils = require 'mp.utils'
2+
3+
MULTIMEDIA = table.concat({
4+
'*.aac',
5+
'*.avi',
6+
'*.flac',
7+
'*.flv',
8+
'*.m3u',
9+
'*.m3u8',
10+
'*.m4v',
11+
'*.mkv',
12+
'*.mov',
13+
'*.mp3',
14+
'*.mp4',
15+
'*.mpeg',
16+
'*.mpg',
17+
'*.oga',
18+
'*.ogg',
19+
'*.ogv',
20+
'*.opus',
21+
'*.wav',
22+
'*.webm',
23+
'*.wmv',
24+
}, ';')
25+
26+
SUBTITLES = table.concat({
27+
'*.ass',
28+
'*.srt',
29+
'*.ssa',
30+
'*.sub',
31+
'*.txt',
32+
}, ';')
33+
34+
function PowerShell(opts)
35+
return function()
36+
local template = opts.template or [[& {
37+
Add-Type -AssemblyName System.Windows.Forms;
38+
[Windows.Forms.Application]::EnableVisualStyles();
39+
$dialog = New-Object Windows.Forms.OpenFileDialog;
40+
$dialog.Filter = %q;
41+
$dialog.Title = %q;
42+
$dialog.InitialDirectory = %q;
43+
$dialog.Multiselect = $true;
44+
$dialog.ShowHelp = $true;
45+
$dialog.ShowDialog() > $null;
46+
Write-Output $dialog.FileNames;
47+
$dialog.Dispose();
48+
}]]
49+
local path = mp.get_property('path')
50+
path = path == nil and '' or utils.split_path(
51+
utils.join_path(utils.getcwd(), path)
52+
)
53+
local ontop = mp.get_property_native('ontop')
54+
mp.set_property_native('ontop', false)
55+
local powershell = utils.subprocess {
56+
args = {
57+
'powershell', '-NoProfile', '-Command',
58+
string.format(template, opts.text, opts.title, path)
59+
}, cancellable = false
60+
}
61+
mp.set_property_native('ontop', ontop)
62+
if powershell.status ~= 0 then return end
63+
for file in string.gmatch(powershell.stdout, '[^\r\n]+') do
64+
mp.commandv(opts.args[1], file, opts.args[2])
65+
end
66+
end
67+
end
68+
69+
mp.add_key_binding('Ctrl+f', 'open-files', PowerShell {
70+
title = 'Select Files',
71+
text = 'Multimedia Files|'..MULTIMEDIA,
72+
args = {'loadfile', 'append-play'},
73+
})
74+
mp.add_key_binding('Ctrl+F', 'open-url', PowerShell {
75+
title = 'Open URL',
76+
text = 'Enter the URL to open:',
77+
args = {'loadfile', 'replace'},
78+
template = [[& {
79+
Add-Type -AssemblyName Microsoft.VisualBasic;
80+
$url = [Microsoft.VisualBasic.Interaction]::InputBox(%q, %q);
81+
Write-Output $url;
82+
}]],
83+
})
84+
mp.add_key_binding('Alt+f', 'open-subs', PowerShell {
85+
title = 'Select Subs',
86+
text = 'Subtitle Files|'..SUBTITLES,
87+
args = {'sub-add', 'select'},
88+
})

0 commit comments

Comments
 (0)