AutoHotkey Community

It is currently May 26th, 2012, 4:58 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Spotify Remote
PostPosted: February 20th, 2009, 10:55 am 
Offline

Joined: February 19th, 2009, 6:47 pm
Posts: 1
Spotify Remote:

A small GUI and Hotkey script for Spotify.

Inspired by http://www.autohotkey.com/forum/viewtopic.php?t=39506 and using some ideas from *Can't find the url now, will look it up later*

Code:
#Persistent

DetectHiddenWindows, On
SetTitleMatchMode 2
WinGetTitle, Playing, ahk_class SpotifyMainWindow
WinGetTitle, LastSong, ahk_class SpotifyMainWindow

Mute = Off
k_IsVisible = y
k_MenuItemHide = Hide remote
k_MenuItemShow = Show remote

SetTimer, CheckSong, 500

;--- Menu ---;

Menu, Tray, Add, %k_MenuItemHide%, k_ShowHide
Menu, Tray, Add, Exit, k_MenuExit
Menu, Tray, Default, %k_MenuItemHide%
Menu, Tray, NoStandard

;--- GUI ---;

Gui, Margin, 0, 0
Gui, -Caption +E0x200 +ToolWindow

FontSize = 8

gui, font, norm s%FontSize%, Verdana
FontWidth = %FontSize%
FontWidth *= 5
FontWidthHalf = %FontWidth%
FontWidthHalf /= 2
FontWidthDouble = %FontWidth%
FontWidthDouble *= 2

FontHeight = %FontSize%
FontHeight *= 4
FontHeightHalf = %FontHeight%
FontHeightHalf /= 2

Gui, Add, Button, x0 y0 w%FontWidth% h%FontHeight%, prev
FontX = %FontWidth%
Gui, Add, Button, x%FontX% y0 w%FontWidthDouble% h%FontHeight%, play/pause
FontX += %FontWidthDouble%
Gui, Add, Button, x%FontX% y0 w%FontWidth% h%FontHeight%, next
FontX += %FontWidth%
Gui, Add, Button, x%FontX% y0 w%FontWidthHalf% h%FontHeightHalf%, +
Gui, Add, Button, x%FontX% y%FontHeightHalf% w%FontWidthHalf% h%FontHeightHalf%, -
FontX += %FontWidthHalf%
Gui, Add, Button, x%FontX% y0 w%FontWidth% h%FontHeight%, mute

Gui, Show
k_IsVisible = y

WinGet, k_ID, ID, A   ; Get its window ID.
WinGetPos,,, k_WindowWidth, k_WindowHeight, A

SysGet, k_WorkArea, MonitorWorkArea, %k_Monitor%

k_WindowX = %k_WorkAreaRight%
k_WindowX -= %k_WorkAreaLeft%
k_WindowX -= %k_WindowWidth%

k_WindowY = %k_WorkAreaBottom%
k_WindowY -= %k_WindowHeight%

WinMove, A,, %k_WindowX%, %k_WindowY%
WinSet, AlwaysOnTop, On, ahk_id %k_ID%

return

;--- Buttons ---;

Buttonprev:
ControlSend, ahk_parent, ^{Left}, ahk_class SpotifyMainWindow
return

Buttonplay/pause:
ControlSend, ahk_parent, {space}, ahk_class SpotifyMainWindow
WinGetTitle, Playing, ahk_class SpotifyMainWindow
if Playing = Spotify
   ToolTip, Paused
return

Buttonnext:
ControlSend, ahk_parent, ^{Right}, ahk_class SpotifyMainWindow
return

Button+:
ControlSend, ahk_parent, ^{Up}, ahk_class SpotifyMainWindow
return

Button-:
ControlSend, ahk_parent, ^{Down}, ahk_class SpotifyMainWindow
return

Buttonmute:
if Mute != On
{   Mute = On
   ToolTip, Mute On
}
else
{   Mute = Off
   ToolTip, Playing %Playing%
}
ControlSend, ahk_parent, ^+{Down}, ahk_class SpotifyMainWindow
SetTimer, RemoveToolTip, 1500
return

;--- Aliases ---;

CheckSong:
WinGetTitle, Playing, ahk_class SpotifyMainWindow
if Playing != %LastSong%
{   StringTrimLeft, Playing, Playing, 10
   ToolTip, %Playing%
   SetTimer, RemoveToolTip, 1500
   If Mute = On
{
      ControlSend, ahk_parent, ^+{Down}, ahk_class SpotifyMainWindow
      Mute = Off
}
}
WinGetTitle, LastSong, ahk_class SpotifyMainWindow
return

RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return

k_ShowHide:
if k_IsVisible = y
{
   Gui, Cancel
   Menu, Tray, Rename, %k_MenuItemHide%, %k_MenuItemShow%
   k_IsVisible = n
}
else
{
   Gui, Show
   Menu, Tray, Rename, %k_MenuItemShow%, %k_MenuItemHide%
   k_IsVisible = y
}
return

k_MenuExit:
ExitApp

;--- HotKeys ---;

!Left::
ControlSend, ahk_parent, ^{Left}, ahk_class SpotifyMainWindow
return

!Up::
ControlSend, ahk_parent, {space}, ahk_class SpotifyMainWindow
WinGetTitle, Playing, ahk_class SpotifyMainWindow
if Playing = Spotify
   ToolTip, Paused
return

!Down::
if Mute != On
{   Mute = On
   ToolTip, Mute On
}
else
{   Mute = Off
   ToolTip, Playing %Playing%
}
ControlSend, ahk_parent, ^+{Down}, ahk_class SpotifyMainWindow
SetTimer, RemoveToolTip, 1500
return

!Right::
ControlSend, ahk_parent, ^{Right}, ahk_class SpotifyMainWindow
return

!NumpadAdd::
ControlSend, ahk_parent, ^{Up}, ahk_class SpotifyMainWindow
return

!NumpadSub::
ControlSend, ahk_parent, ^{Down}, ahk_class SpotifyMainWindow
return


Hotkeys:

Alt+Left
Previous Song

Alt+Up
Play/Pause

Alt+Right
Next Song

Alt+Numpad+
Volume Up

Alt+Numpad-
Volume Down

Alt+Down
Mute, with a twist.
Using the non-paying version of spotify you will sometimes get comercial breaks between two songs. This mute function is made so that when the title changes it unmute again. This is for the possibility to "skip" the annoying messages. (Would be glad if we could skip the debate about if thats morally right or not. :)

Known problems:
Sometimes when Spotify changes songs, while using the mute function, it doesn't disable the mute correctly. It will show the volume is back to normal in the Spotify window, but it's still muted. This is solved by sending any command to Spotify. So its probably a bug in the Spotify-client. It's possible that I could fix this by sending blank commands, but I don't really like to write such a "dirty hack" before I know what the real problem is.

Hope you enjoy.
(Its probably quite obvious that I know crap about programing, and that I'm just writing random code and hoping that it works. So feel free to criticize. :)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group