Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Control Winamp via systray icons


  • Please log in to reply
9 replies to this topic
Serenity
  • Members
  • 1271 posts
  • Last active:
  • Joined: 07 Nov 2004
Whilst theres several apps available that do the same thing, I wrote this script mainly to demonstrate that this can be done with AutoHotkey. :)

Running the main script places six icons in your systray like so:

Posted Image

Each icon has its own function (play, pause, stop etc) and changes to red temporarily to confirm the icon has been clicked.

You can download all the scripts and icons needed from here.

Some issues:
* In order for the main script to close all other icons along with itself you will need to compile each child script, or scriptlets as I like to think of them. :)
* Currently, clicking on the "Winamp" icon only activates Winamp. If Winamp is not running it will open it. I would like for the main "Winamp" icon to toggle all Winamp windows (main window, including playlist and equaliser windows) between active/minimized states.

Main script:
; this script enables winamp to be controlled via icons in the systray

; specify the path to winamp here:
path = d:\winamp\winamp.exe

#Persistent ; keep program running
#SingleInstance force

Run, prev.ahk
sleep, 100
Run, play.ahk
sleep, 100
Run, pause.ahk
sleep, 100
Run, stop.ahk
sleep, 100
Run, next.ahk
sleep, 100

menu, tray, icon, winamp.ico, 1
menu, tray, tip, winamp systray

Menu, Tray, NoStandard ; only use this menu
Menu, Tray, Click, 1  ; Remove this line if you prefer double-click vs. single-click.

Menu, Tray, Add, &Winamp, Winamp
Menu, Tray, Default, &Winamp

Menu, Tray, Add ; separator

Menu, Tray, Add, (&1) Play, Play
Menu, Tray, Add, (&2) Pause, Pause
Menu, Tray, Add, (&3) Stop, Stop

Menu, Tray, Add ; separator

Menu, Tray, Add, (&4) Prev, Prev
Menu, Tray, Add, (&5) Next, Next

Menu, Tray, Add ; separator

Menu, Tray, Add, &Reload, Reload
Menu, Tray, Add, &Suspend, Suspend
Menu, Tray, Add, E&xit, Exit
return

; PostMessage, Msg [, wParam, lParam, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]

Winamp:
IfWinNotExist, ahk_class Winamp v1.x
 {
  Run, %path%
  WinActivate, ahk_class Winamp v1.x
  return
 }
  IfWinNotActive, ahk_class Winamp v1.x
 {
  WinActivate, ahk_class Winamp v1.x
  return
 }
WinMinimize, ahk_class Winamp v1.x  
return


Play:
PostMessage, 0x111, 40045,,, ahk_class Winamp v1.x 
return

Pause:
PostMessage, 0x111, 40046,,, ahk_class Winamp v1.x
return

Stop:
PostMessage, 0x111, 40047,,, ahk_class Winamp v1.x
return

Prev:
PostMessage, 0x111, 40044,,, ahk_class Winamp v1.x
return

Next:
PostMessage, 0x111, 40048,,, ahk_class Winamp v1.x
return

Reload:
Reload
return

Suspend:
Suspend
return

Exit:
Process, Close, prev.exe
Process, Close, play.exe
Process, Close, pause.exe
Process, Close, stop.exe
Process, Close, next.exe
Exitapp

Scriptlets:

; prev.ahk

#Persistent
#SingleInstance force

Menu, Tray, NoStandard ; only use this menu
Menu, Tray, Click, 1  ; Remove this line if you prefer double-click vs. single-click.

menu, tray, tip, previous track
menu, tray, icon, prev.ico, 1

Menu, Tray, Add, Previous, Previous
Menu, Tray, Default, Previous
Menu, Tray, Add, Exit, Exit
return

Previous:
PostMessage, 0x111, 40044,,, ahk_class Winamp v1.x
PostMessage, 0x111, 40047,,, ahk_class Winamp v1.x ; remove this line if you prefer it to skip and play automatically
GoSub, Icon
return

Exit:
ExitApp

Icon:
menu, tray, icon, red_prev.ico, 1
sleep, 200
menu, tray, icon, prev.ico, 1

; play.ahk

#Persistent
#SingleInstance force

Menu, Tray, NoStandard ; only use this menu
Menu, Tray, Click, 1 ; Remove this line if you prefer double-click vs. single-click.

menu, tray, tip, play track
menu, tray, icon, play.ico, 1

Menu, Tray, Add, Play, Play
Menu, Tray, Default, Play
Menu, Tray, Add, Exit, Exit
return

Play:
PostMessage, 0x111, 40045,,, ahk_class Winamp v1.x 
GoSub, Icon
return

Exit:
ExitApp

Icon:
menu, tray, icon, red_play.ico, 1
sleep, 200
menu, tray, icon, play.ico, 1

; pause.ahk

#Persistent
#SingleInstance force

Menu, Tray, NoStandard ; only use this menu
Menu, Tray, Click, 1 ; Remove this line if you prefer double-click vs. single-click.

menu, tray, tip, pause track
menu, tray, icon, pause.ico, 1

Menu, Tray, Add, Pause, Pause
Menu, Tray, Default, Pause
Menu, Tray, Add, Exit, Exit
return

Pause:
PostMessage, 0x111, 40046,,, ahk_class Winamp v1.x
GoSub, Icon
return

Exit:
ExitApp

Icon:
menu, tray, icon, red_pause.ico, 1
sleep, 200
menu, tray, icon, pause.ico, 1

; stop.ahk

#Persistent
#SingleInstance force

Menu, Tray, NoStandard ; only use this menu
Menu, Tray, Click, 1 ; Remove this line if you prefer double-click vs. single-click.

menu, tray, tip, stop track
menu, tray, icon, stop.ico, 1

Menu, Tray, Add, Stop, Stop
Menu, Tray, Default, Stop
Menu, Tray, Add, Exit, Exit
return

Stop:
PostMessage, 0x111, 40047,,, ahk_class Winamp v1.x
GoSub, Icon
return

Exit:
ExitApp

Icon:
menu, tray, icon, red_stop.ico, 1
sleep, 200
menu, tray, icon, stop.ico, 1

; next.ahk

#Persistent
#SingleInstance force

Menu, Tray, NoStandard ; only use this menu
Menu, Tray, Click, 1  ; Remove this line if you prefer double-click vs. single-click.

menu, tray, tip, next track
menu, tray, icon, next.ico, 1

Menu, Tray, Add, Next, Next
Menu, Tray, Default, Next
Menu, Tray, Add, Exit, Exit
return

Next:
PostMessage, 0x111, 40048,,, ahk_class Winamp v1.x
PostMessage, 0x111, 40047,,, ahk_class Winamp v1.x ; remove this line if you prefer it to skip and play automatically
GoSub, Icon
return

Exit:
ExitApp

Icon:
menu, tray, icon, red_next.ico, 1
sleep, 200
menu, tray, icon, next.ico, 1

"Anything worth doing is worth doing slowly." - Mae West
Posted Image

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004
I like it... but I won't actually use it because I viciously guard my screen real estate, especially in the tray.

One thing that might incline me to give it a try, though, is if it were made toolbar-capable. This can be done easily my making scripts that perform their function when they're run, then immediately exit. In this way, you could add shortcuts to these scripts to a folder, then add that folder to the taskbar as a toolbar. Voila! Instant Winamp controls! You can even customize the icons, since they're shortcuts.

You up to the challenge? :twisted:

Serenity
  • Members
  • 1271 posts
  • Last active:
  • Joined: 07 Nov 2004
lol! Well I don't use it either as I already have Winampbar.

The toolbar idea is nice, but it means running something like ShortPopUp from the quicklaunch to get at the menu items, which means the functions are more than one click away. I prefer the idea of a small always-on-top toolwindow. For example, QuickTask puts the taskbar into a floating always-on-top tool window. To recreate something like that with AutoHotkey would be really cool. :)
"Anything worth doing is worth doing slowly." - Mae West
Posted Image

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004
No, you don't need an app... on XP (and I'm pretty sure on older ones too, but I don't have one to test on), you can simply right-click the taskbar, go to the Toolbars submenu, then click New Toolbar.... This shows a dialog where you can select a folder. The contents of the folder will be displayed as quicklaunch-style icons.

Btw, VP's awesome. I've been wanting to sign up for some time, as their site is one of the best, but I'm the worst procrastinator the world has ever seen. (Well, fine, not the world, but at least this forum :lol: )

As for recreating a QuickTask-esque toolbar with AHK, I think it sounds possible, but it wouldn't be pretty. You could probably even use the existing icons you've made. I'll add it to my "I'll get around to it sometime" list. :wink: (This list is also my "boredom" list, and as I have disgustingly large amounts of free time, this list usually runs down pretty fast)

Serenity
  • Members
  • 1271 posts
  • Last active:
  • Joined: 07 Nov 2004
Using the toolbar is good, I prefer using ShortPopUp in the quicklaunch for the control the .ini file offers.

I compiled stripped down versions the systray scriptlets (each .exe turns out to be 178kb!) so that I could specify my own icons in the menus.

Posted Image

The scriptlets for the toolbar/quicklaunch version:

; prev.ahk

#NoTrayIcon
#SingleInstance force

PostMessage, 0x111, 40044,,, ahk_class Winamp v1.x
; play.ahk

#NoTrayIcon
#SingleInstance force

PostMessage, 0x111, 40045,,, ahk_class Winamp v1.x
; pause.ahk

#NoTrayIcon
#SingleInstance force

PostMessage, 0x111, 40046,,, ahk_class Winamp v1.x
; stop.ahk

#NoTrayIcon
#SingleInstance force

PostMessage, 0x111, 40047,,, ahk_class Winamp v1.x
; next.ahk

#NoTrayIcon
#SingleInstance force

PostMessage, 0x111, 40048,,, ahk_class Winamp v1.x

"Anything worth doing is worth doing slowly." - Mae West
Posted Image

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004
Heh... you don't really have to compile, you know. All you have to do is make a shortcut to it, and then you can set the icon. Unless you're worried about that annoying little arrow, in which case I'd suggest MenuApp (IMHO a really good custom menu program, which I think has an option to turn off those darn arrows).

Serenity
  • Members
  • 1271 posts
  • Last active:
  • Joined: 07 Nov 2004
I totally forgot you could use shortcuts! :) (No problem with the little arrow here, disabled that in the registry.) Now all we need is to be able to show icons for menu entries in menus made with AutoHotkey. 8)
"Anything worth doing is worth doing slowly." - Mae West
Posted Image

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004
That is already planned, suggested by yours truly. :D You won't see it in the planned features list, though, because it's still on the "informal" list.

Pallie
  • Members
  • 56 posts
  • Last active: Feb 23 2005 11:53 PM
  • Joined: 05 Jul 2004
Serenity

I love it. There is no substitute for having you own version of existing programs so that you can build in your own functions. I plan to use this as a basis for controlling WINAMP remotely over the LAN.

Mike

Serenity
  • Members
  • 1271 posts
  • Last active:
  • Joined: 07 Nov 2004
Thanks Mike. :)
"Anything worth doing is worth doing slowly." - Mae West
Posted Image