# Copyright 2021, P. Lutus # Released under the GPL $sig = ' [DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); [DllImport("user32.dll")] public static extern int SetForegroundWindow(IntPtr hwnd); ' Add-Type -MemberDefinition $sig -name NativeMethods -namespace Win32 # set "pr=n" to limit video resolution # to avoid YouTube stalling the download # example settings 1080, 720, 576, 360, 240 # set to "-1" to specify best available resolution # but this setting may create stalls during video playback $pr=576 echo "VLC clipboard launcher ($pr): keep this window open." echo "To use, copy a video URL to the clipboard." echo "To exit, close this window." Set-Clipboard -value " " while ($true) { $url = Get-Clipboard if ($url -match "https?://.*") { stop-process -name vlc -ErrorAction SilentlyContinue echo "Playing: $url ..." $proc = Start-Process vlc "--preferred-resolution $pr -f $url vlc://quit" -WindowStyle Maximized -Passthru sleep(1) $hwnd = $proc.MainWindowHandle $null = [Win32.NativeMethods]::ShowWindowAsync($hwnd, 2) $null = [Win32.NativeMethods]::SetForegroundWindow($hwnd) $null = [Win32.NativeMethods]::ShowWindowAsync($hwnd, 3) # erase current clipboard URL Set-Clipboard -value " " } sleep(1) }