Jump to content
Sign in to follow this  

Trying to show what is playing on Spotify by using the CMD window through AutoIt

Recommended Posts

Hey guys,

So i'm fairly new at using Autoit and am trying to automate most of what I use Spotify for I have managed to create next song pause/play and favorite song things, but as of yet my code to show me what is playing through Auto it is failing to work.

I know that the CMD script I have used works but it doesn't seem to work when used through the Autoit script.

Here is my code:

#include <GUIConstantsEx.au3>
#include <INet.au3>

$nResult = Explain

GUICreate("Spotify", 215, 200, 209, 29)
$button1 = GUICtrlCreateButton("Exit", 10, 40, 87, 34)
$button2 = GUICtrlCreateButton("Refresh", 121, 40, 87, 34)
$label1 = GUICtrlCreateLabel("Playing:" & $nResult, 10, 20, 136, 20)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
        Case $button1
        Case $button2

Func button1()
EndFunc   ;==>button1

Func button2()
    GUICtrlSetData($label1,"Playing:" & $nResult)
EndFunc   ;==>button2

Func Explain()
     Local $nResult = Run(@ComSpec & 'tasklist /fi "ImageName eq Spotify.exe" /v /fo list | find /N " " |findstr /r \[10]', @SystemDir, @SW_SHOW, 6)
     Return StdoutRead ($nResult)

 EndFunc   ;==>Explain


Hopefully you can easily spot where I am going wrong?!?!


Cheers in advance.

Share this post

Link to post
Share on other sites

Quite a few issues in how the code is laid out.

@ComSpec needs a /k or /c proceeding

Your $nResult variable declaration would need quotes around it to make it a string.

I wrote a full GUI for Spotify to use on a Windows tablet because it was too hard to push the tiny little buttons on a 8" tablet, so I made big buttons with a GUI, and the tablet screen should shut off, so the code also keeps the tablet awake.

I'll just post the full code incase you see anything you like, but it does have a "now playing" piece that you can look at.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIButton.au3>
#include <WindowsConstants.au3>

FileInstall("VolDown.jpg", @TempDir & "\VolDown.jpg", 1)
FileInstall("Mute.jpg", @TempDir & "\Mute.jpg", 1)
FileInstall("VolUp.jpg", @TempDir & "\VolUp.jpg", 1)
FileInstall("Back.jpg", @TempDir & "\Back.jpg", 1)
FileInstall("Forward.jpg", @TempDir & "\Forward.jpg", 1)
FileInstall("Play.jpg", @TempDir & "\Play.jpg", 1)
FileInstall("Pause.jpg", @TempDir & "\Pause.jpg", 1)
FileInstall("Spotify.jpg", @TempDir & "\Spotify.jpg", 1)

AdLibRegister("KeepAlive", 60000)

$Form1 = GUICreate("Patrick's Tablet Audio GUI", 621, 545, 192, 124)
$Button1 = GUICtrlCreatePic(@TempDir & "\VolDown.jpg", 56, 416, 90, 90)
$Button2 = GUICtrlCreatePic(@TempDir & "\Mute.jpg", 269, 418, 90, 90)
$Button3 = GUICtrlCreatePic(@TempDir & "\VolUp.jpg", 493, 418, 90, 90)
$Button4 = GUICtrlCreatePic(@TempDir & "\Back.jpg", 60, 223, 90, 90)
$Button5 = GUICtrlCreatePic(@TempDir & "\Play.jpg", 225, 169, 180, 180)
$Button6 = GUICtrlCreatePic(@TempDir & "\Forward.jpg", 491, 222, 90, 90)
$Button7 = GUICtrlCreatePic(@TempDir & "\Spotify.jpg", 260, 20, 110, 110)
$Label1 = GUICtrlCreateLabel("Spotify Now Playing Export Tool", 36, 140, 457, 24)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")

GUICtrlSetImage($Button5, @TempDir & "\Pause.jpg")
Global $vToggle = 1
Global $sWindow
Global $sWindow2

While 1
    If $sWindow <> $sWindow2 Then
        $sWindow = WinGetTitle("[CLASS:SpotifyMainWindow]", "")
        GUICtrlSetData($Label1, $sWindow)
        If StringRegExp($sWindow, "(?i)spotify") Then
            GUICtrlSetImage($Button5, @TempDir & "\Play.jpg")
            GUICtrlSetImage($Button5, @TempDir & "\Pause.jpg")
     $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
        Case $Button1
            Send("{VOLUME_DOWN 5}")
        Case $Button2
        Case $Button3
            Send("{VOLUME_UP 5}")
        Case $Button4
        Case $Button5
            ;$vToggle +=1
            ;If MOD($vToggle, 2) Then
            ;    GUICtrlSetImage($Button5, @TempDir & "\Pause.jpg")
            ;    GUICtrlSetImage($Button5, @TempDir & "\Play.jpg")
        Case $Button6
        Case $Button7
            If ProcessExists("Spotify.exe") Then
                ShellExecute(@UserProfileDir & "\AppData\Roaming\Spotify\Spotify.exe")
    $sWindow2 = WinGetTitle("[CLASS:SpotifyMainWindow]", "")

Func KeepAlive()
    $aCurrentPos = MouseGetPos()
    MouseMove($aCurrentPos[0]+1, $aCurrentPos[1])
    MouseMove($aCurrentPos[0]-1, $aCurrentPos[1])


Share this post

Link to post
Share on other sites

Sorry to open up an old thread but I have been playing around Spotify automation. 


This command doesn't seem to work for me?  Is it no longer supported in the Spotify client?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...