Open youtube link on any browser & play using autohotkeyπ
-
- Requires Autohotkey (v2.0).
- Create ahk file, enter code:
#Requires AutoHotkey v2.0 ;ββ Settings ββ videoURL := "PUT_URL_HERE" ;ββ Locate Browser (Firefox in this examaple) ββ path64 := A_ProgramFiles . "\Mozilla Firefox\firefox.exe" path86 := A_ProgramFiles . " (x86)\Mozilla Firefox\firefox.exe" if FileExist(path64) firefoxPath := path64 else if FileExist(path86) firefoxPath := path86 else { MsgBox("Could not find firefox.exe.", "Error") ExitApp() } ;ββ Open in a new tab ββ Run( Format('{} -new-tab "{}"', firefoxPath, videoURL) ) ;ββ Wait for YouTube tab/window ββ SetTitleMatchMode(2) if !WinWait("YouTube", "", 10) { MsgBox("YouTube window not found.", "Error") ExitApp() } ;ββ Maximize & focus ββ hWnd := WinExist("YouTube") WinMaximize(hWnd) WinActivate(hWnd) WinWaitActive(hWnd, "", 5) ;ββ Let it load & play ββ Sleep(7000) Send("{Space}") ExitApp
- In triggercmd add new command.
- Command - location of file(C:\Users\Admin\Desktop\yourfile.ahk)
LINUX(Requires X11, does not work with Wayland yet) - https://github.com/phil294/AHK_X11
Code (have not tested):#!/usr/bin/env ahk_x11 #NoEnv #SingleInstance force ;ββ Settings ββ playlistURL = PUT_URL_HERE ;ββ Open in a new tab of your default Firefox ββ ; The --new-tab flag will reuse an existing window if there is one. Run firefox --new-tab "%playlistURL%" ;ββ Wait (up to 10s) for any window with βYouTubeβ in its title ββ WinWait YouTube,,,10 if ErrorLevel { MsgBox YouTube window not found. ExitApp } ;ββ Maximize & focus ββ WinMaximize YouTube WinActivate YouTube WinWaitActive YouTube,,,5 ;ββ Give time for the page to load ββ Sleep 7000 ;ββ Toggle play/pause via Space ββ Send {Space} ExitApp
- chmod +x yourfile.ahk