Benjamino Posted May 22, 2017 Share Posted May 22, 2017 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) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $button1 button1() Case $button2 button2() EndSwitch WEnd Func button1() Exit 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. Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted May 22, 2017 Share Posted May 22, 2017 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. expandcollapse popup#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") GUISetState(@SW_SHOW) 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") Else GUICtrlSetImage($Button5, @TempDir & "\Pause.jpg") EndIf EndIF $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Send("{VOLUME_DOWN 5}") Case $Button2 Send("{VOLUME_MUTE}") Case $Button3 Send("{VOLUME_UP 5}") Case $Button4 Send("{MEDIA_PREV}") Case $Button5 Send("{MEDIA_PLAY_PAUSE}") ;$vToggle +=1 ;If MOD($vToggle, 2) Then ; GUICtrlSetImage($Button5, @TempDir & "\Pause.jpg") ;Else ; GUICtrlSetImage($Button5, @TempDir & "\Play.jpg") ;EndIf Case $Button6 Send("{MEDIA_NEXT}") Case $Button7 If ProcessExists("Spotify.exe") Then ProcessClose("Spotify.exe") Else ShellExecute(@UserProfileDir & "\AppData\Roaming\Spotify\Spotify.exe") EndIf EndSwitch Sleep(10) $sWindow2 = WinGetTitle("[CLASS:SpotifyMainWindow]", "") WEnd Func KeepAlive() $aCurrentPos = MouseGetPos() MouseMove($aCurrentPos[0]+1, $aCurrentPos[1]) MouseMove($aCurrentPos[0]-1, $aCurrentPos[1]) EndFunc Benjamino 1 Link to comment Share on other sites More sharing options...
Benjamino Posted May 23, 2017 Author Share Posted May 23, 2017 You my good sir are a legend! Is there a way for me to mark this post as resolved/completed. Thank you very much. Link to comment Share on other sites More sharing options...
simonmason Posted February 2, 2019 Share Posted February 2, 2019 Sorry to open up an old thread but I have been playing around Spotify automation. Send("{MEDIA_PLAY_PAUSE}") This command doesn't seem to work for me? Is it no longer supported in the Spotify client? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now