Skip to content

Instantly share code, notes, and snippets.

@jeferandom
Last active September 5, 2024 00:38
Show Gist options
  • Save jeferandom/a512fb813a677ef649ee4f2af60ce136 to your computer and use it in GitHub Desktop.
Save jeferandom/a512fb813a677ef649ee4f2af60ce136 to your computer and use it in GitHub Desktop.
Script to mute windows when it detects Spotify Advertisement on windows with autohotkey V1
; Define a flag to track the mute state
isMuted := false
; Function to mute the system volume
MuteVolume() {
Run, C:\nircmd\nircmd.exe mutesysvolume 1
}
; Function to unmute the system volume
UnmuteVolume() {
Run, C:\nircmd\nircmd.exe mutesysvolume 0
}
; Function to check window titles for the word "Advertisement"
CheckWindowTitles() {
global isMuted
windowTitles := []
; Get a list of all windows
WinGet, id, list
; Loop through all windows
Loop, %id%
{
; Get the window ID
this_id := id%A_Index%
; Get the window title
WinGetTitle, this_title, ahk_id %this_id%
; Add the title to the array
windowTitles.Push(this_title)
}
; Check if any window title contains the word "Advertisement"
containsAdvertisement := false
for index, title in windowTitles {
if InStr(title, "Advertisement") {
containsAdvertisement := true
break
}
}
; Mute or unmute based on the presence of "Advertisement"
if containsAdvertisement {
if !isMuted {
MuteVolume()
isMuted := true
}
} else {
if isMuted {
UnmuteVolume()
isMuted := false
}
}
}
; Set a timer to check window titles every second
SetTimer, CheckWindowTitles, 1000
; Hotkey to manually mute/unmute for testing
F4:: ; altShiftB es ^!b:: y tecla mute es Volume_Mute:: y F4 es F4
if isMuted {
UnmuteVolume()
isMuted := false
} else {
MuteVolume()
isMuted := true
}
return
; Function to check window titles
CheckWindowTitles:
CheckWindowTitles()
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment