Last active
June 5, 2017 21:51
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(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.