Search code examples
autohotkey

how to use auto hotkey to play my liked songs


i used this code

^+!l::
SetTitleMatchMode, 2
IfWinExist, Spotify
{
    WinActivate
    Send, ^l
}
else
{
    Run, "C:\Users\YourUsername\AppData\Roaming\Spotify\Spotify.exe"
    WinWait, Spotify
    WinActivate
    Send, ^l
}
return

but I keep getting errors like this code contains syntax errors function call requrs a space or ( only use a comma between parameters

i tried solving the problem with chat gpt but i keep getting erors i am on v2


Solution

  • #Requires AutoHotkey v2.0
    
    ^+!l::
    {
        if WinExist("ahk_exe Spotify.exe")
        {
            WinActivate
            if WinWaitActive("ahk_exe Spotify.exe", , 2)
                Send "^l"
        }
        else
        {
            Run "C:\Users\YourUsername\AppData\Roaming\Spotify\Spotify.exe"
            if WinWait("ahk_exe Spotify.exe", , 5)
            {
                WinActivate
                if WinWaitActive("ahk_exe Spotify.exe", , 5)
                {   
                    Sleep 2000
                    Send "^l"
                }
            }
        }
    }
    

    To get familiar with AutoHotkey, read the Beginner Tutorial.