Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Is it possible to have an 'always alive' toolbar button (Read 3231 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Is it possible to have an 'always alive' toolbar button

I use fb2k with Columns UI.

I have been adding custom buttons to my fb2k layout, some are via the standard toolbar and some are via a WSH Panel Mod panel.
After a lot of playing around, I have noticed that it is not possible to have a button which will always run regardless if there
is nothing selected or playing in the playlist.

This particular button I had in mind is using the foo_run (Run services) component to run a VBS script which launches a custom
pop-up menu of my own creation. I want to get access to my pop-up menu at any time while foobar2000 is running, irrespective
of the playlist activity.

I can't seem to get it to work.
The buttons called via the WSH script will only run relative to a playing track in the playlist; if no playing track, then no working button.
The buttons called via the Toolbar will only run relative to a selected item in the playlist; if no selected item, then no working button.

While foobar2000 is running, if you go to "View -> Console" then the console window will pop up, irrespective of the playlist activity
or any other state.

Basically, I want a toolbar button with the same capability. Is it possible to do this (from a basic layout editing perspective)?

Is it possible to have an 'always alive' toolbar button

Reply #1
it's perfectly possible to have a WSH panel mod button work at any time independent of any playlist selection/playback.

Is it possible to have an 'always alive' toolbar button

Reply #2
The buttons called via the Toolbar will only run relative to a selected item in the playlist; if no selected item, then no working button.
You like to call a command that act like one from the main menu (independent of any selection) but foo_run commands are placed in context menu and therefore require a selection.

Is it possible to have an 'always alive' toolbar button

Reply #3
marc2003, I can't do this alone I need your help; please elaborate and offer some working WSH code for one button ...PLEASE.

Is it possible to have an 'always alive' toolbar button

Reply #4
as it's only one button, the whole panel reacts to the mouse click...

Code: [Select]
var WshShell = new ActiveXObject("WScript.Shell");
var img = gdi.Image("path\\to\\image.png");

function on_paint(gr) {
    gr.DrawImage(img, 0, 0, 20, 20, 0, 0, img.Width, img.Height);
}

function on_mouse_lbtn_up(x, y) {
    try {
        //put your command in the quotes. if running a local file, remember to use double backslashes in the path like in the img line above.
        WshShell.Run("http://hydrogenaudio.org");
    } catch(e) {
    }
}


on the line beginning gr.Draw... the first 0 is the left margin, the 2nd 0 is the top margin, and the 2 20s are width and height respectively. you can change those but don't edit the other stuff on the same line.

edit: file>preferences>tools>wsh panel mod. make sure safe mode is disabled. you need to do this if running external commands.

Is it possible to have an 'always alive' toolbar button

Reply #5
Your code works perfect marc +++++ ...5 gold stars for you! ...Thanks a lot.

It ran a DOS Batch file perfectly and independently of the playlist.

One last question about your script;
I run foobar2000 in portable mode, and I tried to enter the path to my image as: "%fb2k_path%images\\M.png" but it did not get accepted.
So I entered the path as absolute: "F:\\music\\foobar2000\\images\\M.png" and the panel then worked.
Is it possible to enter relative paths in the WSH script ?

Is it possible to have an 'always alive' toolbar button

Reply #6
there's no such thing as %fb2k_path% (even if it did exist, you'd have to use it with the fb.TitleFormat function in WSH panel mod)

in WSH panel mod, you can use these...

fb.FoobarPath
fb.ProfilePath (points to %appdata%\foobar2000 in normal mode or the same as fb.FoobarPath in portable mode)

Is it possible to have an 'always alive' toolbar button

Reply #7
Thanks again marc.
For anybody else reading this thread looking for the  exact same function, here is marc's WSH code fully tested and with helpful comments added
ready for your "copy-paste" pleasure into your own foobar2000:
Code: [Select]
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// *          WSH Panel Mod script for foobar2000                  *
// *                      by marc2003                                *
// *                                                                *
// *            'ALWAYS ALIVE' TOOLBAR BUTTON                      *
// * which works independently of active, selected or playing states *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//
// * Notes:
//  Variables to use for retrieving relative path to foobar2000.exe:
//  ("fb.FoobarPath"  or  "fb.ProfilePath") . "fb.ProfilePath" points
//  to "%appdata%\foobar2000" in normal mode or the same as "fb.FoobarPath"
//  in portable mode .
//
// * Important !!!!!!
//  Go to "File->Preferences->Tools>WSH Panel Mod" and make sure safe mode
//  is disabled . You need to do this if running external commands .
//
// * WSH Panel Mod Configuration:
//  Script Engine ..............: JScript
//  Edge Style .................: None
//  Pseudo Transparent .........: Unchecked
//  Grab Focus .................: Checked
//  Delay Load .................: Unchecked
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


//////////////////////////////////////////////////////////////////////////
//  PROGRAM DESCRIPTION:  Launch a custom pop-up menu via a batch file  //
//////////////////////////////////////////////////////////////////////////

var WshShell = new ActiveXObject("WScript.Shell");
//var img = gdi.Image("path\\to\\image.png");
var img = gdi.Image(fb.ProfilePath + "images\\M.bmp");

function on_paint(gr) {
    // gr.DrawImage(img, left_margin, top_margin, width, height, 0, 0, img.Width, img.Height);
    gr.DrawImage(img, 0, 0, 20, 20, 0, 0, img.Width, img.Height);
}

function on_mouse_lbtn_up(x, y) {
    try {
        //put your command in the quotes. if running a local file, remember to use double backslashes in the path like in the img line above.
        WshShell.Run(fb.ProfilePath + "tools\\Menu-Launcher\\launcher.bat");
    } catch(e) {
    }
}