Code: Select all
#singleinstance force
Spotify:
Tooltip
WinGet _windows, List
Loop % _windows {
_hwnd := _windows%A_Index%
WinGet _process, ProcessName, ahk_id %_hwnd%
WinGetTitle _title, ahk_id %_hwnd%
} until (_process == "Spotify.exe" && _title != "")
if (_process == "Spotify.exe") && !((_title ~= "-") || (_title ~= "(?i)^Spotify(\sFree)?$") || (_title = "drag")) {
Tooltip % "1"
Process Close, %_process%
Process WaitClose, %_process%, 60
Tooltip % "2"
_A := WinExist("A")
Run %A_AppData%\Spotify\Spotify.exe --minimized
WinWait Spotify
Tooltip % "3"
WinWait Spotify Free
WinActivate ahk_id %_A%
Sleep 1000
Send {Media_Next}
Tooltip % "Spotify Ad Blocked!"
Sleep 10000
}
Sleep 10
Goto Spotify
return
Explanation - The way this script works is that it checks to see if there are any windows that are associated with the Spotify.exe process. If found, then it checks to see if the name has a hyphen, as in Artist - Song Name. Generally Advertisements don't have a hyphen in them. It then closes Spotify and restarts it!