AutoHotkey Community

It is currently May 27th, 2012, 5:19 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 38 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject: Great work ^dallas
PostPosted: September 29th, 2009, 1:09 pm 
Offline

Joined: September 29th, 2009, 1:02 pm
Posts: 1
That's a neat script ^dallas! I had just knocked something together very similar, although I missed the check for Spotify in the tray!

Is there a specific reason you use
WinActivate, ahk_class SpotifyMainWindow
and then
WinWaitActive, ahk_class SpotifyMainWindow
I checked the docs but I don't understand the reason for both checks?

Great work again!
cheers,
Rob


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Great work ^dallas
PostPosted: October 3rd, 2009, 9:46 pm 
rob_henry wrote:
That's a neat script ^dallas! I had just knocked something together very similar, although I missed the check for Spotify in the tray!

Is there a specific reason you use
WinActivate, ahk_class SpotifyMainWindow
and then
WinWaitActive, ahk_class SpotifyMainWindow
I checked the docs but I don't understand the reason for both checks?

Great work again!
cheers,
Rob


Hi Rob,

WinWaitActive was just to make it absolutely sure the window is active before proceeding, but you're right, it's probably unnecessary quoting the docs "Six attempts will be made to activate the target window over the course of 60ms. Thus, it is usually unnecessary to follow WinActivate with WinWaitActive or IfWinNotActive."

And now when I look more closely the docs it looks like it might actually wait indefinitely in a case of some error. To make it more reliable I think it should look more like this:

Code:
^+F11::
{      
   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 the taskbar
   IfWinExist, ahk_class SpotifyMainWindow
   {
      WinActivate, ahk_class SpotifyMainWindow
      WinWaitActive, ahk_class SpotifyMainWindow,,5
      if ErrorLevel
      {
          MsgBox, WinWait timed out.
         return
      }
      add_song()
      WinMinimize, ahk_class SpotifyMainWindow

      MouseMove, original_mouse_x, original_mouse_y
      WinActivate, %original_window_title%
      
      return
   }
   
   ;Spotify in the traybar
   DetectHiddenWindows, On
   IfWinExist, ahk_class SpotifyMainWindow
   {
      WinRestore, ahk_class SpotifyMainWindow
      WinActivate, ahk_class SpotifyMainWindow
      WinWaitActive, ahk_class SpotifyMainWindow,,5
      if ErrorLevel
      {
          MsgBox, WinWait timed out.
         return
      }
      add_song()
      WinClose, ahk_class SpotifyMainWindow
      
      MouseMove, original_mouse_x, original_mouse_y
      WinActivate, %original_window_title%
      
      return
   }
   
   ;Spotify active
   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
   }
}


Report this post
Top
  
Reply with quote  
 Post subject: My Attempt
PostPosted: November 10th, 2009, 12:26 am 
Offline

Joined: March 11th, 2006, 9:07 am
Posts: 12
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
}




Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 31st, 2010, 12:22 pm 
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?

Thanks :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 23rd, 2011, 9:56 pm 
Offline

Joined: January 23rd, 2011, 9:53 pm
Posts: 1
zzzTAG wrote:
ok, happy with this for now :D

Code:
SetTitleMatchMode 2

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

; "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 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
}

RefreshTrayTip:
WinGetTitle, now_playing, ahk_class SpotifyMainWindow
StringTrimLeft, playing, now_playing, 10
if(playing != playingsave) {
  TrayTip, Now playing:, %playing%., 10 , 16 
}
playingsave := playing
return


How can i make the info balloon pop up every time a new song has started?


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Add hotkey for "Queue"?
PostPosted: March 13th, 2011, 5:44 pm 
I don't know if this is possible but can you add a hotkey for Spotify's "Queue" option?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 15th, 2011, 2:40 am 
ahk is a powerful tool that can also be used to capture the screen if this interests you more.

Print screen to file and load to gui is the simplest but not most elegant solution to do this, I think.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 15th, 2011, 3:02 am 
Offline
User avatar

Joined: May 18th, 2010, 3:10 pm
Posts: 1179
Location: Sweden
I'm gonna make a Spotify controller script at some time. For now, you'll have to do with this very simple /NP code snippet. Type /NP to get the effect of... Now playing: Spotify - Igor Stravinsky – Symphony Of Psalms: I. Exaudi Oratorionem Mea, Domine

Code:
::/np::
WinGetTitle, NP, ahk_class SpotifyMainWindow
Send,Now playing: %NP%
; Now playing: Spotify - Movie Sounds Unlimited – Now We Are Free (From Gladiator)


Edit: This might have been linked, but for those that wanna check out an awesome Spotify controller (called Stopify), check this topic: http://www.autohotkey.com/forum/viewtopic.php?t=66771

EDIT2: It's done, atleast an initial version: Hotkeys & notifications, in a slim look: http://www.autohotkey.com/forum/viewtopic.php?t=69653. Will implement a nicer looking GUI, a visible controller, some feedback on whether a song is playing or not & volume, and album image. Atleast some of them.

_________________
~sumon Appifyer AHK Nova halted Recommended: AHK_L (Why?)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 38 posts ]  Go to page Previous  1, 2, 3

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, HotkeyStick, XstatyK and 84 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