AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Spotify and AHK
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Sansana
Guest





PostPosted: Sun Jan 04, 2009 10:23 pm    Post subject: Hotkeys + Now playing in clipboard Reply with quote

Hi!
I modded zzzTAG's latest version of the script and came up with this:

Code:

SetTitleMatchMode 2

; "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 pause
^UP::
{
DetectHiddenWindows, On
ControlSend, ahk_parent, {space}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off
return
}

; "CTRL + DOWN"  for info
^Down::
{
DetectHiddenWindows, On
SetTitleMatchMode 2
WinGetTitle, now_playing, ahk_class SpotifyMainWindow
StringTrimLeft, playing, now_playing, 10
DetectHiddenWindows, Off
clipboard = %playing%`r`n
return
}


For my needs I removed the tray notification and added global hotkey for play/pause (Ctrl + UP). I've changed the info function (Ctrl + DOWN) so it doesn't show in tray either, but copies the song's artist and title to clipboard so you can paste it wherever you want.

Now playing: Eric Serra – Little Light of Love (End Titles version)
~

So the keys are:
ctrl + left - previous
ctrl + right - next
ctrl + up - play/pause
ctrl + down - info goes to clipboard

Hope somebody will find this useful!

PS. Any ideas how to get album's name?
Back to top
Zawaq



Joined: 03 Jan 2009
Posts: 4

PostPosted: Mon Jan 05, 2009 6:27 am    Post subject: Re: Hotkeys + Now playing in clipboard Reply with quote

Sansana wrote:
Hi!
I modded zzzTAG's latest version of the script and came up with this:

Code:

SetTitleMatchMode 2

; "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 pause
^UP::
{
DetectHiddenWindows, On
ControlSend, ahk_parent, {space}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off
return
}

; "CTRL + DOWN"  for info
^Down::
{
DetectHiddenWindows, On
SetTitleMatchMode 2
WinGetTitle, now_playing, ahk_class SpotifyMainWindow
StringTrimLeft, playing, now_playing, 10
DetectHiddenWindows, Off
clipboard = %playing%`r`n
return
}


For my needs I removed the tray notification and added global hotkey for play/pause (Ctrl + UP). I've changed the info function (Ctrl + DOWN) so it doesn't show in tray either, but copies the song's artist and title to clipboard so you can paste it wherever you want.

Now playing: Eric Serra – Little Light of Love (End Titles version)
~

So the keys are:
ctrl + left - previous
ctrl + right - next
ctrl + up - play/pause
ctrl + down - info goes to clipboard

Hope somebody will find this useful!

PS. Any ideas how to get album's name?


I took your modified script an added volume keys.

Code:

SetTitleMatchMode 2

; "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 pause
^UP::
{
DetectHiddenWindows, On
ControlSend, ahk_parent, {space}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off
return
}

; "CTRL + ALT + UP"  for volume up
^!Up::
{
DetectHiddenWindows, On
ControlSend, ahk_parent, ^{up}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off
return
}

; "CTRL + ALT + DOWN"  for volume down
^!Down::
{
DetectHiddenWindows, On
ControlSend, ahk_parent, ^{down}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off
return
}

; "CTRL + DOWN"  for info
^Down::
{
DetectHiddenWindows, On
SetTitleMatchMode 2
WinGetTitle, now_playing, ahk_class SpotifyMainWindow
StringTrimLeft, playing, now_playing, 10
DetectHiddenWindows, Off
clipboard = %playing%`r`n
return
}


volume up: Ctrl + Alt + Up (Alternative AltGr + Up)
volume down: Ctrl + Alt + Down (Alternative AltGr + Down)
Back to top
View user's profile Send private message
chripopper
Guest





PostPosted: Thu Jan 29, 2009 8:54 pm    Post subject: Reply with quote

Here's a script i wrote for spotify. I've copied some code from this thread and from all over the forum, i also wrote some myself. It got some hotkeys, song notification, and so on. Look at the code or just try it out!

Btw this is my first script ever so it may not be the best. Feel free to do whatever you want with it.


Code:
SetTitleMatchMode 2
#WinActivateForce
#singleinstance force

#persistent
RegRead, SPATH, HKEY_CLASSES_ROOT, spotify\DefaultIcon,
StringGetPos, POS, SPATH, \spotify.exe
StringReplace, SPATH, SPATH, `,0 ,,A
StringReplace, SPATH, SPATH, ",,A

Run, %SPATH%



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


SetTimer, RefreshTrayTip2, 1000
Gosub, RefreshTrayTip2  ; Call it once to get it started right away.


SetTimer, SpotifyExit, 5000
Gosub, SpotifyExit  ; Call it once to get it started right away.




Menu, Tray, NoStandard
Menu, tray, add, Show/Hide Spotify, spotify
Menu, tray, add
Menu, tray, add, Play/Pause, Playp  ; Creates a new menu item.
Menu, Tray, add, Next, l_defaultaction
Menu, Tray, Default, Next
Menu, Tray, Click, 1
Menu, tray, add, Previous, prev
Menu, tray, add
Menu, tray, add, Exit, Ex




{DetectHiddenWindows, Off
   Sleep, 1050
 WinWaitClose, Spotify, , 15
 DetectHiddenWindows, On
RegExMatch(TrayIcons("spotify.exe"), "(?<=idn: )\d+", idn) ; This finds out the ID of the Tray Icon of "yourapp.exe"
HideTrayIcon(idn) ; This hides that icon :D
}
return



l_defaultaction:
if tray_clicks > 0 ; SetTimer already started, so we log the keypress instead.
{
   tray_clicks += 1
   return
}
; Otherwise, this is the first press of a new series. Set count to 1 and start
; the timer:
tray_clicks = 1
SetTimer, tray_clicks_check, 400 ; Wait for more presses within a 400 millisecond window.
return

tray_clicks_check:
SetTimer, tray_clicks_check, off
if tray_clicks = 1 ; The key was pressed once.
{
DetectHiddenWindows, On
ControlSend, ahk_parent, ^{Right}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off
}
else if tray_clicks = 2 ; The key was pressed twice.
{
WinShow, ahk_Class SpotifyMainWindow
WinActivate, ahk_Class SpotifyMainWindow
}
else if tray_clicks > 2
{
DetectHiddenWindows, On
ControlSend, ahk_parent, ^{Left}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off
}
; Regardless of which action above was triggered, reset the count to
; prepare for the next series of presses:
tray_clicks = 0
return


; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;




/*
WM_MOUSEMOVE   = 0x0200
WM_LBUTTONDOWN   = 0x0201
WM_LBUTTONUP   = 0x0202
WM_LBUTTONDBLCLK= 0x0203
WM_RBUTTONDOWN   = 0x0204
WM_RBUTTONUP   = 0x0205
WM_RBUTTONDBLCLK= 0x0206
WM_MBUTTONDOWN   = 0x0207
WM_MBUTTONUP   = 0x0208
WM_MBUTTONDBLCLK= 0x0209

PostMessage, nMsg, uID, WM_RBUTTONDOWN, , ahk_id %hWnd%
PostMessage, nMsg, uID, WM_RBUTTONUP  , , ahk_id %hWnd%
*/















TrayIcons(sExeName = "spotify.exe")
{
   WinGet,   pidTaskbar, PID, ahk_class Shell_TrayWnd
   hProc:=   DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
   pProc:=   DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0, "Uint", 32, "Uint", 0x1000, "Uint", 0x4)
   idxTB:=   GetTrayBar()
      SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_BUTTONCOUNT
   Loop,   %ErrorLevel%
   {
      SendMessage, 0x417, A_Index-1, pProc, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_GETBUTTON
      VarSetCapacity(btn,32,0), VarSetCapacity(nfo,32,0)
      DllCall("ReadProcessMemory", "Uint", hProc, "Uint", pProc, "Uint", &btn, "Uint", 32, "Uint", 0)
         iBitmap   := NumGet(btn, 0)
         idn   := NumGet(btn, 4)
         Statyle := NumGet(btn, 8)
      If   dwData   := NumGet(btn,12)
         iString   := NumGet(btn,16)
      Else   dwData   := NumGet(btn,16,"int64"), iString:=NumGet(btn,24,"int64")
      DllCall("ReadProcessMemory", "Uint", hProc, "Uint", dwData, "Uint", &nfo, "Uint", 32, "Uint", 0)
      If   NumGet(btn,12)
         hWnd   := NumGet(nfo, 0)
      ,   uID   := NumGet(nfo, 4)
      ,   nMsg   := NumGet(nfo, 8)
      ,   hIcon   := NumGet(nfo,20)
      Else   hWnd   := NumGet(nfo, 0,"int64"), uID:=NumGet(nfo, 8), nMsg:=NumGet(nfo,12)
      WinGet, pid, PID,              ahk_id %hWnd%
      WinGet, sProcess, ProcessName, ahk_id %hWnd%
      WinGetClass, sClass,           ahk_id %hWnd%
      If !sExeName || (sExeName = sProcess) || (sExeName = pid)
         VarSetCapacity(sTooltip,128), VarSetCapacity(wTooltip,128*2)
      ,   DllCall("ReadProcessMemory", "Uint", hProc, "Uint", iString, "Uint", &wTooltip, "Uint", 128*2, "Uint", 0)
      ,   DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "str", wTooltip, "int", -1, "str", sTooltip, "int", 128, "Uint", 0, "Uint", 0)
      ,   sTrayIcons .= "idx: " . A_Index-1 . " | idn: " . idn . " | Pid: " . pid . " | uID: " . uID . " | MessageID: " . nMsg . " | hWnd: " . hWnd . " | Class: " . sClass . " | Process: " . sProcess . "`n" . "   | Tooltip: " . sTooltip . "`n"
   }
   DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pProc, "Uint", 0, "Uint", 0x8000)
   DllCall("CloseHandle", "Uint", hProc)
   Return   sTrayIcons
}

RemoveTrayIcon(hWnd, uID, nMsg = 0, hIcon = 0, nRemove = 2)
{
   NumPut(VarSetCapacity(ni,444,0), ni)
   NumPut(hWnd , ni, 4)
   NumPut(uID  , ni, 8)
   NumPut(1|2|4, ni,12)
   NumPut(nMsg , ni,16)
   NumPut(hIcon, ni,20)
   Return   DllCall("shell32\Shell_NotifyIconA", "Uint", nRemove, "Uint", &ni)
}

HideTrayIcon(idn, bHide = True)
{
   idxTB := GetTrayBar()
   SendMessage, 0x404, idn, bHide, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_HIDEBUTTON
   SendMessage, 0x1A, 0, 0, , ahk_class Shell_TrayWnd
}

DeleteTrayIcon(idx)
{
   idxTB := GetTrayBar()
   SendMessage, 0x416, idx - 1, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_DELETEBUTTON
   SendMessage, 0x1A, 0, 0, , ahk_class Shell_TrayWnd
}

MoveTrayIcon(idxOld, idxNew)
{
   idxTB := GetTrayBar()
   SendMessage, 0x452, idxOld - 1, idxNew - 1, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd ; TB_MOVEBUTTON
}

GetTrayBar()
{
   ControlGet, hParent, hWnd,, TrayNotifyWnd1  , ahk_class Shell_TrayWnd
   ControlGet, hChild , hWnd,, ToolbarWindow321, ahk_id %hParent%
   Loop
   {
      ControlGet, hWnd, hWnd,, ToolbarWindow32%A_Index%, ahk_class Shell_TrayWnd
      If  Not   hWnd
         Break
      Else If   hWnd = %hChild%
      {
         idxTB := A_Index
         Break
      }
   }
   Return   idxTB
}

Return









; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;














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


; "CTRL + N"  for next
^n::
{
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
}

; "CTRL + ALT + HOME"  for pause
^!HOME::
{
DetectHiddenWindows, On
ControlSend, ahk_parent, {space}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off
return
}

; "CTRL + DOWN"  To show/hide spotify window
^DOWN::
{
DetectHiddenWindows, On
ifWinNotActive, ahk_Class SpotifyMainWindow
{
WinShow, ahk_Class SpotifyMainWindow
WinActivate, ahk_Class SpotifyMainWindow
}
else ifWinActive, ahk_Class SpotifyMainWindow
WinClose, ahk_Class SpotifyMainWindow
DetectHiddenWindows, Off
return
}


; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


RefreshTrayTip:
DetectHiddenWindows, On
WinGetTitle, now_playing, ahk_class SpotifyMainWindow
StringTrimLeft, playing, now_playing, 10
if(playing != playingsave) {
  TrayTip, Now playing:, %playing%, 10 , 16
  SetTimer, RemoveTrayTip, -5000
}
playingsave := playing
return

RemoveTrayTip:
    TrayTip
    return

RefreshTrayTip2:
WinGetTitle, title, ahk_class SpotifyMainWindow
Menu, Tray, Tip, %title%
return




Playp:
{
DetectHiddenWindows, On
ControlSend, ahk_parent, {space}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off
return
}


Ex:
process, close, spotify.exe
ExitApp
return


next:
{
DetectHiddenWindows, On
ControlSend, ahk_parent, ^{Right}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off
return
}

prev:
DetectHiddenWindows, On
ControlSend, ahk_parent, ^{Left}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off
return


spotify:
{
DetectHiddenWindows, Off
ifWinNotExist, ahk_Class SpotifyMainWindow
{
WinShow, ahk_Class SpotifyMainWindow
}
else ifWinExist, ahk_Class SpotifyMainWindow
WinClose, ahk_Class SpotifyMainWindow
return
}

SpotifyExit:
 Sleep, 2000
DetectHiddenWindows, On
IfWinNotExist, ahk_class SpotifyMainWindow
ExitApp
Return
Back to top
Zawaq



Joined: 03 Jan 2009
Posts: 4

PostPosted: Fri Jan 30, 2009 9:15 pm    Post subject: Reply with quote

chripopper wrote:
Here's a script i wrote for spotify. I've copied some code from this thread and from all over the forum, i also wrote some myself. It got some hotkeys, song notification, and so on. Look at the code or just try it out!

Btw this is my first script ever so it may not be the best. Feel free to do whatever you want with it.


Code:
SetTitleMatchMode 2
#WinActivateForce
#singleinstance force

#persistent
RegRead, SPATH, HKEY_CLASSES_ROOT, spotify\DefaultIcon,
StringGetPos, POS, SPATH, \spotify.exe
StringReplace, SPATH, SPATH, `,0 ,,A
StringReplace, SPATH, SPATH, ",,A

Run, %SPATH%



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


SetTimer, RefreshTrayTip2, 1000
Gosub, RefreshTrayTip2  ; Call it once to get it started right away.


SetTimer, SpotifyExit, 5000
Gosub, SpotifyExit  ; Call it once to get it started right away.




Menu, Tray, NoStandard
Menu, tray, add, Show/Hide Spotify, spotify
Menu, tray, add
Menu, tray, add, Play/Pause, Playp  ; Creates a new menu item.
Menu, Tray, add, Next, l_defaultaction
Menu, Tray, Default, Next
Menu, Tray, Click, 1
Menu, tray, add, Previous, prev
Menu, tray, add
Menu, tray, add, Exit, Ex




{DetectHiddenWindows, Off
   Sleep, 1050
 WinWaitClose, Spotify, , 15
 DetectHiddenWindows, On
RegExMatch(TrayIcons("spotify.exe"), "(?<=idn: )\d+", idn) ; This finds out the ID of the Tray Icon of "yourapp.exe"
HideTrayIcon(idn) ; This hides that icon :D
}
return



l_defaultaction:
if tray_clicks > 0 ; SetTimer already started, so we log the keypress instead.
{
   tray_clicks += 1
   return
}
; Otherwise, this is the first press of a new series. Set count to 1 and start
; the timer:
tray_clicks = 1
SetTimer, tray_clicks_check, 400 ; Wait for more presses within a 400 millisecond window.
return

tray_clicks_check:
SetTimer, tray_clicks_check, off
if tray_clicks = 1 ; The key was pressed once.
{
DetectHiddenWindows, On
ControlSend, ahk_parent, ^{Right}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off
}
else if tray_clicks = 2 ; The key was pressed twice.
{
WinShow, ahk_Class SpotifyMainWindow
WinActivate, ahk_Class SpotifyMainWindow
}
else if tray_clicks > 2
{
DetectHiddenWindows, On
ControlSend, ahk_parent, ^{Left}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off
}
; Regardless of which action above was triggered, reset the count to
; prepare for the next series of presses:
tray_clicks = 0
return


; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;




/*
WM_MOUSEMOVE   = 0x0200
WM_LBUTTONDOWN   = 0x0201
WM_LBUTTONUP   = 0x0202
WM_LBUTTONDBLCLK= 0x0203
WM_RBUTTONDOWN   = 0x0204
WM_RBUTTONUP   = 0x0205
WM_RBUTTONDBLCLK= 0x0206
WM_MBUTTONDOWN   = 0x0207
WM_MBUTTONUP   = 0x0208
WM_MBUTTONDBLCLK= 0x0209

PostMessage, nMsg, uID, WM_RBUTTONDOWN, , ahk_id %hWnd%
PostMessage, nMsg, uID, WM_RBUTTONUP  , , ahk_id %hWnd%
*/















TrayIcons(sExeName = "spotify.exe")
{
   WinGet,   pidTaskbar, PID, ahk_class Shell_TrayWnd
   hProc:=   DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
   pProc:=   DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0, "Uint", 32, "Uint", 0x1000, "Uint", 0x4)
   idxTB:=   GetTrayBar()
      SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_BUTTONCOUNT
   Loop,   %ErrorLevel%
   {
      SendMessage, 0x417, A_Index-1, pProc, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_GETBUTTON
      VarSetCapacity(btn,32,0), VarSetCapacity(nfo,32,0)
      DllCall("ReadProcessMemory", "Uint", hProc, "Uint", pProc, "Uint", &btn, "Uint", 32, "Uint", 0)
         iBitmap   := NumGet(btn, 0)
         idn   := NumGet(btn, 4)
         Statyle := NumGet(btn, 8)
      If   dwData   := NumGet(btn,12)
         iString   := NumGet(btn,16)
      Else   dwData   := NumGet(btn,16,"int64"), iString:=NumGet(btn,24,"int64")
      DllCall("ReadProcessMemory", "Uint", hProc, "Uint", dwData, "Uint", &nfo, "Uint", 32, "Uint", 0)
      If   NumGet(btn,12)
         hWnd   := NumGet(nfo, 0)
      ,   uID   := NumGet(nfo, 4)
      ,   nMsg   := NumGet(nfo, 8)
      ,   hIcon   := NumGet(nfo,20)
      Else   hWnd   := NumGet(nfo, 0,"int64"), uID:=NumGet(nfo, 8), nMsg:=NumGet(nfo,12)
      WinGet, pid, PID,              ahk_id %hWnd%
      WinGet, sProcess, ProcessName, ahk_id %hWnd%
      WinGetClass, sClass,           ahk_id %hWnd%
      If !sExeName || (sExeName = sProcess) || (sExeName = pid)
         VarSetCapacity(sTooltip,128), VarSetCapacity(wTooltip,128*2)
      ,   DllCall("ReadProcessMemory", "Uint", hProc, "Uint", iString, "Uint", &wTooltip, "Uint", 128*2, "Uint", 0)
      ,   DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "str", wTooltip, "int", -1, "str", sTooltip, "int", 128, "Uint", 0, "Uint", 0)
      ,   sTrayIcons .= "idx: " . A_Index-1 . " | idn: " . idn . " | Pid: " . pid . " | uID: " . uID . " | MessageID: " . nMsg . " | hWnd: " . hWnd . " | Class: " . sClass . " | Process: " . sProcess . "`n" . "   | Tooltip: " . sTooltip . "`n"
   }
   DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pProc, "Uint", 0, "Uint", 0x8000)
   DllCall("CloseHandle", "Uint", hProc)
   Return   sTrayIcons
}

RemoveTrayIcon(hWnd, uID, nMsg = 0, hIcon = 0, nRemove = 2)
{
   NumPut(VarSetCapacity(ni,444,0), ni)
   NumPut(hWnd , ni, 4)
   NumPut(uID  , ni, 8)
   NumPut(1|2|4, ni,12)
   NumPut(nMsg , ni,16)
   NumPut(hIcon, ni,20)
   Return   DllCall("shell32\Shell_NotifyIconA", "Uint", nRemove, "Uint", &ni)
}

HideTrayIcon(idn, bHide = True)
{
   idxTB := GetTrayBar()
   SendMessage, 0x404, idn, bHide, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_HIDEBUTTON
   SendMessage, 0x1A, 0, 0, , ahk_class Shell_TrayWnd
}

DeleteTrayIcon(idx)
{
   idxTB := GetTrayBar()
   SendMessage, 0x416, idx - 1, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_DELETEBUTTON
   SendMessage, 0x1A, 0, 0, , ahk_class Shell_TrayWnd
}

MoveTrayIcon(idxOld, idxNew)
{
   idxTB := GetTrayBar()
   SendMessage, 0x452, idxOld - 1, idxNew - 1, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd ; TB_MOVEBUTTON
}

GetTrayBar()
{
   ControlGet, hParent, hWnd,, TrayNotifyWnd1  , ahk_class Shell_TrayWnd
   ControlGet, hChild , hWnd,, ToolbarWindow321, ahk_id %hParent%
   Loop
   {
      ControlGet, hWnd, hWnd,, ToolbarWindow32%A_Index%, ahk_class Shell_TrayWnd
      If  Not   hWnd
         Break
      Else If   hWnd = %hChild%
      {
         idxTB := A_Index
         Break
      }
   }
   Return   idxTB
}

Return









; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;














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


; "CTRL + N"  for next
^n::
{
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
}

; "CTRL + ALT + HOME"  for pause
^!HOME::
{
DetectHiddenWindows, On
ControlSend, ahk_parent, {space}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off
return
}

; "CTRL + DOWN"  To show/hide spotify window
^DOWN::
{
DetectHiddenWindows, On
ifWinNotActive, ahk_Class SpotifyMainWindow
{
WinShow, ahk_Class SpotifyMainWindow
WinActivate, ahk_Class SpotifyMainWindow
}
else ifWinActive, ahk_Class SpotifyMainWindow
WinClose, ahk_Class SpotifyMainWindow
DetectHiddenWindows, Off
return
}


; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


RefreshTrayTip:
DetectHiddenWindows, On
WinGetTitle, now_playing, ahk_class SpotifyMainWindow
StringTrimLeft, playing, now_playing, 10
if(playing != playingsave) {
  TrayTip, Now playing:, %playing%, 10 , 16
  SetTimer, RemoveTrayTip, -5000
}
playingsave := playing
return

RemoveTrayTip:
    TrayTip
    return

RefreshTrayTip2:
WinGetTitle, title, ahk_class SpotifyMainWindow
Menu, Tray, Tip, %title%
return




Playp:
{
DetectHiddenWindows, On
ControlSend, ahk_parent, {space}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off
return
}


Ex:
process, close, spotify.exe
ExitApp
return


next:
{
DetectHiddenWindows, On
ControlSend, ahk_parent, ^{Right}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off
return
}

prev:
DetectHiddenWindows, On
ControlSend, ahk_parent, ^{Left}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off
return


spotify:
{
DetectHiddenWindows, Off
ifWinNotExist, ahk_Class SpotifyMainWindow
{
WinShow, ahk_Class SpotifyMainWindow
}
else ifWinExist, ahk_Class SpotifyMainWindow
WinClose, ahk_Class SpotifyMainWindow
return
}

SpotifyExit:
 Sleep, 2000
DetectHiddenWindows, On
IfWinNotExist, ahk_class SpotifyMainWindow
ExitApp
Return

Looks good, but is it possible to do so the info disappear when you hit CTRL + UP again?
Back to top
View user's profile Send private message
chripopper
Guest





PostPosted: Sat Jan 31, 2009 2:21 am    Post subject: Reply with quote

Dunno, but as you can see i made a timer that removes it after 5 seconds, change it if you want. Regarding the remove of song notification with ctrl+up, I will take a look at it tomorrow when im not so drunk Very Happy

Thanks btw!
Back to top
Phoenix



Joined: 23 Sep 2005
Posts: 48

PostPosted: Mon Feb 02, 2009 10:50 am    Post subject: Reply with quote

Is there anyway to retrive the album cover from spotify?
Back to top
View user's profile Send private message
ToJa92
Guest





PostPosted: Mon Feb 23, 2009 9:44 pm    Post subject: Reply with quote

Phoenix wrote:
Is there anyway to retrive the album cover from spotify?


I don't think so, but I could be wrong. I think I read somewhere that a API is in the making.. But I'm unsure what functions will be provided.
Back to top
drue
Guest





PostPosted: Sat Feb 28, 2009 12:00 am    Post subject: I could be the biggest idiot... Reply with quote

Yeah, i could be really really stupid now, but I thought I'd might ask anyway. I've created the script I wanted, and it works great, but is there a way i can make it automatically start when i fire up Spotify? Like something i can add in the shortcut preferences? Would be great if that was the case...
Back to top
ToJa92
Guest





PostPosted: Sat Mar 14, 2009 12:50 pm    Post subject: Re: I could be the biggest idiot... Reply with quote

drue wrote:
Yeah, i could be really really stupid now, but I thought I'd might ask anyway. I've created the script I wanted, and it works great, but is there a way i can make it automatically start when i fire up Spotify? Like something i can add in the shortcut preferences? Would be great if that was the case...


Zawaq's script launches spotify if it's not running , just look and see if you can find anything. Which means you can put it in spotifys directory, reassign shortcuts to that program and it will launch spotify with hotkeys.
Back to top
Zawaq



Joined: 03 Jan 2009
Posts: 4

PostPosted: Sun Mar 15, 2009 1:09 pm    Post subject: Re: I could be the biggest idiot... Reply with quote

ToJa92 wrote:
drue wrote:
Yeah, i could be really really stupid now, but I thought I'd might ask anyway. I've created the script I wanted, and it works great, but is there a way i can make it automatically start when i fire up Spotify? Like something i can add in the shortcut preferences? Would be great if that was the case...


Zawaq's script launches spotify if it's not running , just look and see if you can find anything. Which means you can put it in spotifys directory, reassign shortcuts to that program and it will launch spotify with hotkeys.


My script? No, it's chripopper's script. Cool
Back to top
View user's profile Send private message
norz



Joined: 21 Nov 2008
Posts: 2

PostPosted: Fri May 08, 2009 4:49 pm    Post subject: Reply with quote

chripopper wrote:
Here's a script i wrote for spotify. I've copied some code from this thread and from all over the forum, i also wrote some myself. It got some hotkeys, song notification, and so on. Look at the code or just try it out! (...)

Works well for me, thank you very much! Smile

I would be interesting to make it work with snarl to have bigger, prettier, and more customizable notifications, but I don't know if this is possible or how hard it would be.
Example:


NB: there's also Toastify, a dedicated app, that does global shortcuts and notifications for Spotify (requires .net 3.5): http://toastify.codeplex.com/
Back to top
View user's profile Send private message
KeyOh



Joined: 14 May 2009
Posts: 1

PostPosted: Thu May 14, 2009 6:54 pm    Post subject: Multi tasking iTunes and Spotify Reply with quote

Thought maybe there were more people than me using both iTunes and Spotify as a media player. So I made a quite simple script controlling both without having to many hotkeys.

Control+shift+s Sets Spotify as the active media player
Control+shift+i Sets iTunes as the active media player

Control+Alt+Right Next Song
Control+Alt+Left Previous Song
Control+Alt+Up Volume Up
Control+Alt+Down Volume Down
Control+Alt+Space Play/Mute

Control+shift+a Runs/Activates/Minimizes media player

Code:

SetTitleMatchMode 2

^+i::
FileDelete, %ProgramFiles%\AutoHotkey\activeplayer.mvd
FileAppend, i, %ProgramFiles%\AutoHotkey\activeplayer.mvd
TrayTip, Active Media Player:, iTunes
SetTimer, RemoveTrayTip, 1000
return

^+s::
FileDelete, %ProgramFiles%\AutoHotkey\activeplayer.mvd
FileAppend, s, %ProgramFiles%\AutoHotkey\activeplayer.mvd
TrayTip, Active Media Player:, Spotify
SetTimer, RemoveTrayTip, 1000
return


^!right:: ; Control+Alt+Right : Next Song
;---------------------------------------------------------------------------
FileRead, ActivePlayer, %ProgramFiles%\AutoHotkey\activeplayer.mvd

If (ActivePlayer = "s") ; For Spotify
{
   DetectHiddenWindows, On
   ControlSend, ahk_parent, ^{Right}, ahk_class SpotifyMainWindow
   DetectHiddenWindows, Off
   return
}
Else If (ActivePlayer = "i") ; For iTunes
{
   DetectHiddenWindows, On
   ControlSend, ahk_parent, ^{right}, iTunes ahk_class iTunes
   DetectHiddenWindows, Off
   return
}
return


^!left:: ; Control+Alt+Left : Previous Song
;---------------------------------------------------------------------------
FileRead, ActivePlayer, %ProgramFiles%\AutoHotkey\activeplayer.mvd

If (ActivePlayer = "s") ; For Spotify
{
   DetectHiddenWindows, On
   ControlSend, ahk_parent, ^{Left}, ahk_class SpotifyMainWindow
   DetectHiddenWindows, Off
   return
}
Else If (ActivePlayer = "i") ; For iTunes
{
   DetectHiddenWindows, On
   ControlSend, ahk_parent, ^{left}, iTunes ahk_class iTunes
   DetectHiddenWindows, Off
   return
}
return



^!up:: ; Control+Alt+Up : Volume Up
;---------------------------------------------------------------------------
FileRead, ActivePlayer, %ProgramFiles%\AutoHotkey\activeplayer.mvd

If (ActivePlayer = "s") ; For Spotify
{
   DetectHiddenWindows, On
   ControlSend, ahk_parent, ^{up}, ahk_class SpotifyMainWindow
   DetectHiddenWindows, Off
   return
}
Else If (ActivePlayer = "i") ; For iTunes
{
   DetectHiddenWindows, On
   ControlSend, ahk_parent, ^{up}, iTunes ahk_class iTunes
   DetectHiddenWindows, Off
   return
}
return



^!down:: ; Control+Alt+Down : Volume Down
;---------------------------------------------------------------------------
FileRead, ActivePlayer, %ProgramFiles%\AutoHotkey\activeplayer.mvd

If (ActivePlayer = "s") ; For Spotify
{
   DetectHiddenWindows, On
   ControlSend, ahk_parent, ^{down}, ahk_class SpotifyMainWindow
   DetectHiddenWindows, Off
   return
}
Else If (ActivePlayer = "i") ; For iTunes
{
   DetectHiddenWindows, On
   ControlSend, ahk_parent, ^{down}, iTunes ahk_class iTunes
   DetectHiddenWindows, Off
   return
}
return



^!space:: ; Control+Alt+Space : Play/Pause
;---------------------------------------------------------------------------
FileRead, ActivePlayer, %ProgramFiles%\AutoHotkey\activeplayer.mvd

If (ActivePlayer = "s") ; For Spotify
{
   DetectHiddenWindows, On
   ControlSend, ahk_parent, {space}, ahk_class SpotifyMainWindow
   DetectHiddenWindows, Off
   return
}
Else If (ActivePlayer = "i") ; For iTunes
{
   DetectHiddenWindows, On
   ControlSend, ahk_parent, {space}, iTunes ahk_class iTunes
   DetectHiddenWindows, Off
   return
}
return


^+a:: ; Control+Shift+A : Run/Activate/Minimize active media player
;---------------------------------------------------------------------------
FileRead, ActivePlayer, %ProgramFiles%\AutoHotkey\activeplayer.mvd

If (ActivePlayer = "s") ; For Spotify
{
   IfWinNotExist, ahk_class SpotifyMainWindow
   {
      Run %ProgramFiles%\Spotify\Spotify.exe  ;launch program
      return
   }
   IfWinExist, ahk_class SpotifyMainWindow ; toggle minimize/restore
   {
      IfWinNotActive ; restores window
      WinActivate
      Else
      WinMinimize ; minimizes windows
      return
   }
}

Else If (ActivePlayer = "i") ; For iTunes
{
   IfWinNotExist, ahk_class iTunes
   {
      Run %ProgramFiles%\iTunes\iTunes.exe  ;launch program
      return
   }
   IfWinExist, ahk_class iTunes ; toggle minimize/restore
   {
      IfWinNotActive ; restores window
      WinActivate
      Else
      WinMinimize ; minimizes windows
      return
   }
}
return


RemoveTrayTip:
SetTimer, RemoveTrayTip, Off
TrayTip
return



hope you like it
Back to top
View user's profile Send private message
norz



Joined: 21 Nov 2008
Posts: 2

PostPosted: Sat May 16, 2009 8:26 pm    Post subject: Reply with quote

norz wrote:
I would be interesting to make it work with snarl to have bigger, prettier, and more customizable notifications, but I don't know if this is possible or how hard it would be.
Example:

Growl is now also available for Windows:
http://www.growlforwindows.com/gfw/
I don't know which one will be the best in the coming years though.
Back to top
View user's profile Send private message
kyf



Joined: 12 Sep 2009
Posts: 7

PostPosted: Sat Sep 19, 2009 4:41 am    Post subject: Reply with quote

Hi,
If you are interested in getting album art and album name into your notification, you can use the last.fm api

for example:
http://ws.audioscrobbler.com/2.0/?method=track.getinfo&api_key=b25b959554ed76058ac220b7b2e0a026&artist=radiohead&track=creep

I've used it in my script:
http://www.autohotkey.com/forum/viewtopic.php?t=49002
Back to top
View user's profile Send private message
dallas^
Guest





PostPosted: Sat Sep 26, 2009 10:09 pm    Post subject: Reply with quote

I wrote a small script that adds the currently playing song on Spotify to the defined playlist by the hotkey. Feel free to make it better!

Code:
^+F12::
{      
   playlist_number = 1 ;Playlist number from the top
   
   SetDefaultMouseSpeed, 0
   CoordMode, Mouse, Screen
   MouseGetPos, original_mouse_x, original_mouse_y
   WinGetActiveTitle, original_window_title
   
   ;Spotify in taskbar
   IfWinExist, ahk_class SpotifyMainWindow
   {
      WinActivate, ahk_class SpotifyMainWindow
      WinWaitActive, ahk_class SpotifyMainWindow
      add_song()
      WinMinimize, ahk_class SpotifyMainWindow

      MouseMove, original_mouse_x, original_mouse_y
      WinActivate, %original_window_title%
      
      return
   }
   
   ;Spotify in traybar
   DetectHiddenWindows, On
   IfWinExist, ahk_class SpotifyMainWindow
   {
      WinRestore, ahk_class SpotifyMainWindow
      WinActivate, ahk_class SpotifyMainWindow
      WinWaitActive, ahk_class SpotifyMainWindow
      add_song()
      WinClose, ahk_class SpotifyMainWindow
      
      MouseMove, original_mouse_x, original_mouse_y
      WinActivate, %original_window_title%
      
      return
   }
   
   ;Spotify on top
   add_song()
   {
      WinGetPos, X, Y, Width, Height, ahk_class SpotifyMainWindow
      MouseClick, right, X+50, Y+Height-70
      Sleep, 50
      ControlSend, ahk_parent, {DOWN}{DOWN}{DOWN}{RIGHT}, ahk_class SpotifyMainWindow
      
      x = 1
      While x < playlist_number
      {
         x++
         ControlSend, ahk_parent, {DOWN}, ahk_class SpotifyMainWindow
      }
      ControlSend, ahk_parent, {ENTER}, ahk_class SpotifyMainWindow
      Sleep, 50
   }
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group