Skip to content

Instantly share code, notes, and snippets.

@craigmjohnston
Last active June 5, 2017 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigmjohnston/67233423b32b8fd12bec98c6916d5698 to your computer and use it in GitHub Desktop.
Save craigmjohnston/67233423b32b8fd12bec98c6916d5698 to your computer and use it in GitHub Desktop.
AutoHotkey script for saving current song to your music. Moves to Spotify, rightclicks the currently playing song's title, checks the pixel colour of a certain position to find out the size of the context menu (it's wider if you've already added the song) and then saves it if it isn't already and moves back to what you were doing before.
/*
Spotify "Save to Music"
Based on: http://superuser.com/a/879589
Fires on Ctrl+Shift+L, but obviously you can change that to whatever you want.
*/
^+l::
spotify = ahk_class SpotifyMainWindow
IfWinExist, %spotify%
{
;Store active window and mouse position.
WinGetActiveTitle, activeWindow
MouseGetPos x, y, winID
;Activate Spotify.
WinActivate %spotify%
WinWaitActive %spotify%
;Get maximised status
WinGet, isMaximised, MinMax
;Clear any context menus
Send {Escape down}{Escape up}
;Right click near the song title in the "Now Playing" box.
WinGetPos, , , , spotifyHeight, %spotify%
MouseClick, Right, 68, spotifyHeight - (isMaximised = 1 ? 105 : 83), 1, 0
PixelGetColor, pixelColor, 68+174, spotifyHeight - (isMaximised = 1 ? 105 : 83)
if (pixelColor != 0x333333) {
;Move down to 'Add to your music' and hit enter
loop, 5 {
Send {Down down}{Down up}
}
Send {Enter down}{Enter up}
} else {
;Already added, so close context menu
Send {Escape down}{Escape up}
}
;Restore original window and mouse position.
WinActivate ahk_id %winID%
MouseMove %x%, %y%
}
Return
@craigmjohnston
Copy link
Author

Edited it just now so that it works if the window is maximised or not. Before it would only work if it was maximised.

Also now it works no matter how small you've made the sidebar, and regardless of what's in the main window.

@GokuderaElPsyCongroo
Copy link

Hello, thank you for your script but it doesn't work in Spotify's last version. The dialog opens just well but it doesn't do anything after that…

@GokuderaElPsyCongroo
Copy link

GokuderaElPsyCongroo commented Jun 5, 2017

(sorry for double post)

That one works

!A::
spotify = ahk_class SpotifyMainWindow
IfWinExist, %spotify%
{
;Store active window and mouse position.
WinGetActiveTitle, activeWindow
MouseGetPos x, y, winID

;Activate Spotify.
WinActivate %spotify%
WinWaitActive %spotify%

;Clear any context menus
Send {Escape down}{Escape up}

;Right click near the song title in the "Now Playing" box.
WinGetPos, , , , spotifyHeight, %spotify%
MouseClick, Right, 68, spotifyHeight - (isMaximised = 1 ? 105 : 83), 1, 0

WinGetPos, X, Y, Width, Height, ahk_class SpotifyMainWindow
MouseClick, left, X+265, Y+Height-105
WinActivate ahk_id %winID%
MouseMove %x%, %y%

}

Return

I took it from here (https://autohotkey.com/board/topic/94218-spotify-global-hotkeys-volume-control-skip-songs-current-song-to-clipboard-star-songs-without-opening-spotify/), corrected positions and fused it with yours but I can't figure out how to make your condition work (not a coder or anything lol), so it always clicks on the "plus" without verification. My English is weird, sorry, I am French.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment