Closed ghost closed 7 months ago
Solution:
Created a ALT+TAB.bat
file with:
powershell -c "$wshell = New-Object -ComObject wscript.shell; $wshell.SendKeys('%%{TAB}')
You need "powershell -File"
local function read_time1(_, time_pos)
if time_pos and time_pos > mp.get_property_native('duration', math.huge) - 15 then
local url = mp.get_property("path")
if string.match(url, "youtube") then
if mp.get_property_number('playlist-count') == 1 then
mp.command_native({name = 'subprocess',args = { 'powershell', '-File', mp.command_native({"expand-path", "~~/ALT+TAB.ps1"})} })
mp.unobserve_property(read_time1)
end
end
end
end
mp.register_event('file-loaded', function ()
mp.observe_property('time-pos', 'native', read_time1)
end)
You can also do it directly from lua without any additional files, but sometimes it can get tricky to properly escape everything with more complicated commands:
local function read_time1(_, time_pos)
if time_pos and time_pos > mp.get_property_native('duration', math.huge) - 15 then
local url = mp.get_property("path")
if string.match(url, "youtube") then
if mp.get_property_number('playlist-count') == 1 then
mp.command_native({
name = 'subprocess',
capture_stdout=true,
args = {
'powershell',
'-NoProfile',
'-Command',
'Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force; $wshell = New-Object -ComObject wscript.shell; $wshell.SendKeys(\'%{TAB}\')'
}
})
mp.unobserve_property(read_time1)
end
end
end
end
mp.register_event('file-loaded', function ()
mp.observe_property('time-pos', 'native', read_time1)
end)
Uh, lovely solution, thank you! Now using:
local function read_time1(_, time_pos)
if time_pos and time_pos > mp.get_property_native('duration', math.huge) - 15 then
local url = mp.get_property("path")
if string.match(url, "youtube") then
if mp.get_property_number('playlist-count') == 1 then
mp.command_native({
name = 'subprocess',
capture_stdout=true,
args = {
'powershell',
'-NoProfile',
'-Command',
'$wshell = New-Object -ComObject wscript.shell; $wshell.SendKeys(\'%{TAB}\')'
}
})
mp.unobserve_property(read_time1)
end
end
end
end
mp.register_event('file-loaded', function ()
mp.observe_property('time-pos', 'native', read_time1)
end)
I have this file called
ALT+TAB.ps1
which has the following:this script sends
ALT+TAB
keystroke. testing this script alone without mpv - works.I'm trying to make a user script that will execute this script, here's the script so far (not working):
Any ideas?