This is the early stages of my script, I have some other code that can parse the album/artist/track data from the spotify metadata api.
features,
New context menu for Spotify (disabled)
Next Track
Previous Track
Smart hide / show
Url Catcher
Auto Play Playlist
Auto Play caught Urls
Code:
;
; AutoHotkey Version: 1.x
; Language: English
; Platform: Win9x/NT
; Author: Shannon Prue <genecyber@gmail.com>
;
; Script Function:
; Automate Spotify, folder)
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#Persistent
#SingleInstance force
#Include TrayIcon.ahk
#Include COM.ahk
currentlyPlaying := "loading"
menuCreate()
hideIcon()
SetTimer, spotState, 50
SetTimer, clipMonitor, 50
return
RButton Up::
if WinActive("ahk_class SpotifyMainWindow")
{
;This is where a custom context menu can go
mouseclick, right
;Menu, MyMenu, Show
return
}
else
mouseclick, right
return
^f5::
reload
return
^f4::
exitapp
return
MenuHandler:
MsgBox You selected %A_ThisMenuItem% from the menu %A_ThisMenu%.
return
getUid(proc)
{
DetectHiddenWindows, On
TI := TrayIcons( proc )
StringSplit,TIV, TI, |
uID := RegExReplace( TIV4, "uID: " )
Msg := RegExReplace( TIV5, "MessageID: " )
hWnd := RegExReplace( TIV6, "hWnd: " )
idn := RegExReplace( TIV2, "idn: " )
return idn
}
menuCreate()
{
Menu, MyMenu, Add, Item1, MenuHandler
Menu, MyMenu, Add, Item2, MenuHandler
Menu, MyMenu, Add ; Add a separator line.
; Create another menu destined to become a submenu of the above menu.
Menu, Submenu1, Add, Item1, MenuHandler
Menu, Submenu1, Add, Item2, MenuHandler
; Create a submenu in the first menu (a right-arrow indicator). When the user selects it, the second menu is
displayed.
Menu, MyMenu, Add, My Submenu, :Submenu1
Menu, MyMenu, Add ; Add a separator line below the submenu.
Menu, MyMenu, Add, Item3, MenuHandler ; Add another menu item beneath the submenu.
;Tray Menu
Menu, Tray, NoStandard
Menu, Tray, Add, > Next Song, nextSong
Menu, Tray, Add, < Previous Song, prevSong
Menu, Tray, Add
Menu, Tray, Add, >> Next Playlist, nextPlaylist
Menu, Tray, Add, << Previous Playlist, prevPlaylist
Menu, Tray, Add
Menu, Tray, Add, Open Spotify, showSpot
Menu, Tray, Add, Hide Spotify, hideSpot
Menu, Tray, Add
Menu, Tray, Add, Exit Spotify, exitSpot
return
}
showSpot:
DetectHiddenWindows, on
winactivate, ahk_class SpotifyMainWindow
Process, Exist, spotify.exe
If (ErrorLevel = 0) ; If it is not running
{
run, %A_ProgramFiles%\spotify\spotify.exe
sleep, 1500
WinHide, ahk_class SpotifyMainWindow
sleep, 5000
ControlSend, ahk_parent, {Tab}{Tab}{Tab}{Down}{Down}{Down}{Down}{Del}{Del}{Del}{Del}{Del}{Del}{Del}
{Enter}, ahk_class SpotifyMainWindow
hideIcon()
return
}
WinShow, ahk_class SpotifyMainWindow
WinActivate, ahk_class SpotifyMainWindow
return
hideSpot:
DetectHiddenWindows, on
WinHide, ahk_class SpotifyMainWindow
return
exitSpot:
Process, Close, spotify.exe
return
nextPlaylist:
WinActivate, ahk_class SpotifyMainWindow
ControlSend, ahk_parent, {Down}{Enter}, ahk_class SpotifyMainWindow
WinActivate
return
prevPlaylist:
WinActivate, ahk_class SpotifyMainWindow
ControlSend, ahk_parent, {Up}{Enter}, ahk_class SpotifyMainWindow
WinActivate
return
nextSong:
WinActivate, ahk_class SpotifyMainWindow
ControlSend, ahk_parent, ^{Right}, ahk_class SpotifyMainWindow
return
prevSong:
WinActivate, ahk_class SpotifyMainWindow
ControlSend, ahk_parent, ^{Left}, ahk_class SpotifyMainWindow
return
hideIcon()
{
spotifyIconIdn := getUid("spotify.exe")
hideTrayIcon(spotifyIconIdn, True)
}
spotState:
DetectHiddenWindows, off
IfWinExist, ahk_class SpotifyMainWindow
windowState := "open"
else
windowState := "closed"
DetectHiddenWindows, on
WinGetTitle, clientTitle, ahk_class SpotifyMainWindow
menuState(windowState)
if currentlyPlaying = %clientTitle%
return
else
{
currentlyPlaying := clientTitle
StringTrimLeft, currentlyPlayingTrim, currentlyPlaying, 10
traytip, Now playing:, %currentlyPlayingTrim%., 10 , 16
}
return
menuState(windowState)
{
if windowState = closed
{
Menu, Tray, Disable, Hide Spotify
Menu, Tray, Enable, Open Spotify
}
else
{
Menu, Tray, Enable, Hide Spotify
Menu, Tray, Disable, Open Spotify
}
}
clipMonitor:
if RegexMatch(Clipboard,"http://open.spotify.com.*") {
; conditions are meet
uri := Clipboard
Clipboard := ""
gosub, openSpotUri
}
return
openSpotUri:
{
run, %uri%,,Hide
sleep, 1000
gosub, hideSpot
ControlSend, ahk_parent, {Enter}, ahk_class SpotifyMainWindow
}