Append to (Instead of Overwriting) an Audacious Playlist from Within Firefox

willfe's picture

Maybe I’ve overlooked something stupid, but Mozilla Firefox 2.x (I haven’t tested in 3.x yet) is quite inflexible about options and command-line arguments for external (“helper”) programs. This manifests itself in a number of ways, but the one I’m dealing with today is this:

  • I’ve got Audacious (a music player for Linux) playing a playlist of decent stuff (all streamed internet radio, but that doesn’t matter).
  • I’ve got another .PLS (a “playlist” file) I’d like to add to my existing playlist (stick the new tracks contained in the new playlist at the end of the already-defined playlist in my Audacious player)
  • Audacious is smart enough to know when it’s run to check if another copy is already running; if so, it just tells that other copy to do what you’ve told the new copy to do
  • Audacious defaults to replacing the current playlist with a new file or playlist provided on the command line; to make it append instead, you have to call it with the “—enqueue” command line argument
  • Firefox won’t let me add any command line arguments to a helper program

Dammit. That sucks, except that Linux (any Unix, really) makes it quite simple to fix this kind of breakage with a specialized little script.

I’d call it a “one liner” but it technically has two lines (though one just tells the system which shell to use to run the command found in the second line):

#!/bin/bash
/usr/bin/audacious --enqueue $*

The “$*” bit just tells the script to dump whatever arguments it receives right on the end of command. So, if we call this thing “audacious_enqueue.sh” (convenient, since that’s what I did call it), and then run it thusly:

$ audacious_enqueue.sh http://www.di.fm/mp3/ambient.pls

That script will, in turn, run the following (just as if I’d typed it myself):

$ /usr/bin/audacious --enqueue /www.di.fm/mp3/ambient.pls

Now, when Firefox asks “what the hell should I do with this .PLS file?” I can just tell it to open it in a program, select “Other…,” then give it the name of my script. It figures out the rest automatically, and all is well in the universe.

Yes, Windows can do this, too; it uses “batch files” instead of “scripts” but they’re essentially the same thing. The bitch about doing it with batch files is the syntax is far more archaic (with lots of quoting for that near-guaranteed “Program Files” bit that will appear in the path to the actual binary you’re calling — spaces confuse shells), and there’s a whole lot less flexibility. I haven’t written a batch file for a few years now, so I don’t know if they’ve ever fixed it, but I do know there’s no equivalent of “$*” available from COMMAND.COM. I’m not sure if that’s actually a big deal in this specific instance (Firefox always just sends a properly-escaped URL, always a single argument) so presumably $1 or the equivalent would work, but it’s still something that’s lacking.

In a more sane world, Audacious would just add an option to control the “default” behavior for “someone just handed me a pile of new files” actions, but we live in a very insane world in which XMMS is no longer very reliable on modern systems.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Textual smileys will be replaced with graphical ones.
  • You can use Markdown syntax to format and style the text.
CAPTCHA
This question is here to test whether you are a human visitor and to prevent automated spam submissions.
2 + 13 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.