Autohotkey Script for controlling Youtube media without losing focus on Obsidian

HI. If you take notes in Obsidian while watching Youtube videos in a browser, this AutoHotKey script will allow you to rewind, pause, or fast forward the video without taking your hands off your keyboard, as the focus automatically returns to Obsidian. (The script is tested on Windows 10)

The shortcuts are:

CTRL+J = Rewind
CTRL+K = Pause/Play
CTRL+L = Forward

This script is made for Chrome, but if you have any other browser, you have to change three lines of code. In each line where it says “ahk_exe chrome.exe” change the word chrome to msedge, vivaldi, opera, firefox or brave, depending on your browser.

This script works in the version 1.1 of AutoHotKey. It’s not tested in Version 2.

; In case you have another browser, replace where it says "chrome" 
; by the name of your browser with: "msedge"; "opera", "vivaldi", "firefox" or "brave".

;CONTROLS:
;CTRL+J = Rewind
;CTRL+K = Pause/Play
;CTRL+L = Forwind


#SingleInstance Force
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#InstallKeybdHook

; YOUTUBE (Microsoft-Edge)-OBSIDIAN FOCUS CHANGE: --------------------------------------


^k::YoutubePause("ahk_exe chrome.exe")

YoutubePause(title)
{
	IfWinExist, %title%
		WinActivate
		sleep 15
		Send k
		sleep 15
		{
			IfWinExist, ahk_exe Obsidian.exe
			WinActivate
		}
	

}

return


^j::YoutubeRewind("ahk_exe chrome.exe")

YoutubeRewind(title)
{
	IfWinExist, %title%
		WinActivate
		sleep 15
		Send j
		sleep 15
		{
			IfWinExist, ahk_exe Obsidian.exe
			WinActivate
		}
	

}

return



^l::YoutubeForwind("ahk_exe chrome.exe")

YoutubeForwind(title)
{
	IfWinExist, %title%
		WinActivate
		sleep 15
		Send l
		sleep 15
		{
			IfWinExist, ahk_exe Obsidian.exe
			WinActivate
		}
	

}

return
7 Likes

how to use it ?

Hi Abdelrhman.

1- Download and install the program AutoHotKey: AutoHotkey

2- Open the Notepad and copy/paste the script.

3- Save the script and change the file extension “.txt” by “.ahk”

4- Double click over the file, and you will have the shortcuts available.

2 Likes

thank you

1 Like

Hi Abdelrhman. I added a few lines of code at the start of the script to make it work better. An download the Version v1.1 of autohotkeys. I realize that I forgot to put it. Please, modify the snippet. Thank you.

2 Likes

Thank you , I love AHK👍