Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Spotify and AHK


  • Please log in to reply
37 replies to this topic
zzzztag
  • Guests
  • Last active:
  • Joined: --
First: I loooove spotify.

Second: It has some flaws. I would like to be able to:

1. Use the built in hotkeys without activating the window.
2. Maybe create a GUI that shows what son is currently playing.

Can stuff like this be done at all?

I'd appreciate any push in a good direction to get me started.

Cheers!

Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008
Yes control send will work for this.
Heres the syntax:

ControlSend [, Control, Keys, WinTitle, WinText, ExcludeTitle, ExcludeText]

And heres an example of how you would use it for hotkeys:

ControlSend, , ^p, Spotify
The first param is blank to send it to the window, then the hotkey to send then window title. The rest isn't that important for this.
aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

zzzztag
  • Guests
  • Last active:
  • Joined: --
ty!

got the most important hotkeys going now!

zzzzTAG
  • Guests
  • Last active:
  • Joined: --
trying to expand with a GUI that shows what is playing now.

F10::
{
WinGetTitle, now_playing, ahk_class SpotifyMainWindow
StringTrimLeft, playing, now_playing, 10 
MsgBox, Now playing: %playing%
}

This retrieves the info I need, but how can I put this into a GUI that auto-updates itself instead of a messagebox?

Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008
I recomend using traytip because its easy and can be seen in any window.

Heres an example of how to make a timed traytip:

TrayTip, Timed TrayTip, This will be displayed for 5 seconds.
SetTimer, RemoveTrayTip, 5000
return

RemoveTrayTip:
SetTimer, RemoveTrayTip, Off
TrayTip
return


aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

zzzztag
  • Guests
  • Last active:
  • Joined: --
I'll have a look into the TrayTip. Never heard of it before.

This is my latest effort:

SetTitleMatchMode 2

F12::ControlSend, , ^{Right}, Spotify
F11::ControlSend, , ^{Left}, Spotify

F10::
{
WinGetTitle, now_playing, ahk_class SpotifyMainWindow
StringTrimLeft, playing, now_playing, 10 
Gui,+AlwaysOnTop
Gui, Add, Text,, %playing%
Gui, Show
}

It gets the title, but I cant get it to change when I play new songs, and the first two hotkeys wont work as long as the gui is up.

zzzztag
  • Guests
  • Last active:
  • Joined: --
SetTimer, RefreshTrayTip, 1000
Gosub, RefreshTrayTip  ; Call it once to get it started right away.
return

RefreshTrayTip:
WinGetTitle, now_playing, ahk_class SpotifyMainWindow
StringTrimLeft, playing, now_playing, 10 
TrayTip, Now playing:, %playing%., , 16
return

No matter what I do with the TrayTip function it only shows for a few milliseconds before it is closed.

glok777
  • Members
  • 3 posts
  • Last active: Dec 09 2008 01:44 AM
  • Joined: 09 Dec 2008
This works for me ...


; "WinKey + p"  for previous
#p::
DetectHiddenWindows, On 
ControlSend, ahk_parent, ^{Left}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off 
return 


; "WinKey + n"  for next
#n::
{
DetectHiddenWindows, On 
ControlSend, ahk_parent, ^{Right}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off 
return 
}

; "WinKey + q"  for pause
#q::
{
DetectHiddenWindows, On
ControlSend, ahk_parent, {Space}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off 
return 
}

; "WinKey + 3"  for info
#3::
{
DetectHiddenWindows, On
SetTitleMatchMode 2
WinGetTitle, now_playing, ahk_class SpotifyMainWindow
StringTrimLeft, playing, now_playing, 10
Gui,+AlwaysOnTop
Gui, Add, Text,, %playing%
Gui, Show
DetectHiddenWindows, Off
return
}



zzzztag
  • Guests
  • Last active:
  • Joined: --
Are you sure it updates the GUI if you switch songs?

glok777
  • Members
  • 3 posts
  • Last active: Dec 09 2008 01:44 AM
  • Joined: 09 Dec 2008
No I see that that doesn't work ...

glok777
  • Members
  • 3 posts
  • Last active: Dec 09 2008 01:44 AM
  • Joined: 09 Dec 2008
Strange window update.
I used your example instead and added a test for song change ...

SetTimer, RefreshTrayTip, 1000
playingSave := ""
Gosub, RefreshTrayTip  ; Call it once to get it started right away.
return

RefreshTrayTip:
WinGetTitle, now_playing, ahk_class SpotifyMainWindow
StringTrimLeft, playing, now_playing, 10
if(playing != playingSave) {
  TrayTip, Now playing:, %playing%., , 16
}
playingSave := playing
return


zzzztag
  • Guests
  • Last active:
  • Joined: --
this keeps the traytip up at all times:

SetTitleMatchMode 2

#Persistent
SetTimer, RefreshTrayTip, 1000 
Gosub, RefreshTrayTip  ; Call it once to get it started right away. 
return 

F12::ControlSend, , ^{Right}, Spotify
F11::ControlSend, , ^{Left}, Spotify



RefreshTrayTip: 
WinGetTitle, now_playing, ahk_class SpotifyMainWindow 
StringTrimLeft, playing, now_playing, 10 
TrayTip, Now playing:, %playing%., 29 , 16 
return


zzzTAG
  • Members
  • 15 posts
  • Last active: Apr 01 2014 08:16 AM
  • Joined: 22 Jun 2006
getting there:

SetTitleMatchMode 2 

#Persistent 
SetTimer, RefreshTrayTip, 1000 
playingsave := "" 
Gosub, RefreshTrayTip  ; Call it once to get it started right away. 
return 

; "WinKey + p"  for previous
#p:: 
DetectHiddenWindows, On 
ControlSend, ahk_parent, ^{Left}, ahk_class SpotifyMainWindow 
DetectHiddenWindows, Off 
return 


; "WinKey + n"  for next 
#n:: 
{ 
DetectHiddenWindows, On 
ControlSend, ahk_parent, ^{Right}, ahk_class SpotifyMainWindow 
DetectHiddenWindows, Off 
return 
}

RefreshTrayTip: 
WinGetTitle, now_playing, ahk_class SpotifyMainWindow 
StringTrimLeft, playing, now_playing, 10 
if(playing != playingsave) { 
  TrayTip, Now playing:, %playing%., 10 , 16  
} 
playingsave := playing 
return


zzzTAG
  • Members
  • 15 posts
  • Last active: Apr 01 2014 08:16 AM
  • Joined: 22 Jun 2006
ok, happy with this for now :D

SetTitleMatchMode 2 

#Persistent 
SetTimer, RefreshTrayTip, 1000 
playingsave := "" 
Gosub, RefreshTrayTip  ; Call it once to get it started right away. 
return 

; "CTRL + LEFT"  for previous
^Left:: 
DetectHiddenWindows, On 
ControlSend, ahk_parent, ^{Left}, ahk_class SpotifyMainWindow 
DetectHiddenWindows, Off 
return 


; "CTRL + RIGHT"  for next 
^Right:: 
{ 
DetectHiddenWindows, On 
ControlSend, ahk_parent, ^{Right}, ahk_class SpotifyMainWindow 
DetectHiddenWindows, Off 
return 
}

; "CTRL + UP"  for info
^Up:: 
{ 
DetectHiddenWindows, On 
SetTitleMatchMode 2 
WinGetTitle, now_playing, ahk_class SpotifyMainWindow 
StringTrimLeft, playing, now_playing, 10 
TrayTip, Now playing:, %playing%., 10 , 16
DetectHiddenWindows, Off 
return 
}

RefreshTrayTip: 
WinGetTitle, now_playing, ahk_class SpotifyMainWindow 
StringTrimLeft, playing, now_playing, 10 
if(playing != playingsave) { 
  TrayTip, Now playing:, %playing%., 10 , 16  
} 
playingsave := playing 
return


Zawaq
  • Members
  • 4 posts
  • Last active: Feb 18 2011 12:08 PM
  • Joined: 03 Jan 2009
Thanks for the script! But is there anyway to use OSD instead of traytip for the song information?