Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I open magnet links in Firefox with a command line app, namely transmission-remote?

I think I need to make a packaged app that accepts arguments, and here's what I did so far:

  1. Use Automator to run a shell script with the following:

    transmission-remote -a $@

  2. Save the Automator script as Transmission.app

  3. Choose Transmission.app in Firefox when using it for magnet links

However, pass arguments to this requires:

open Transmission.app --args magnet:etc

I assume Firefox is doing something like: Transmission.app %s, but I can't tell how Firefox is passing arguments to the helper app. I've also tried creating a wrapper shell script and naming it helper.app to no avail.

Alternatively, can Firefox use something like this as a protocol handler, where I can pass in %s?

open Transmission.app --args %s

EDIT: DS answer apparently works on Snow Leopard and Lion, but I'm still problems with blank arguments being sent from Firefox. I'll paste my comment here too:

I've tried the following but only blanks are sent: echo "$@" >> ~/somefile and echo "$*" >> ~/somefile with and without quotes. Perhaps it is my Firefox settings (about:config?). I'm on 19.0.2 (latest), OSX 10.8.2 in case anybody else chimes in...

share|improve this question

I was struggling with the same question. I got it to work, and I think you were missing a small step. Apparently Firefox on Mac, for its "Open With" applications, doesn't pass arguments via command line or environment variables or any other unix-like method. It uses Mac's Launch Services. Automator can translate these to command line arguments. The following works on Snow Leopard:

  1. Start up Automator, selecting Application for "Choose a template for your workflow".
  2. Find the Action "Run Shell Script", and drag or double-click to add it.
  3. For "Pass input" dropdown: choose "As arguments" <-- I think that's the step you are missing.
  4. For "Shell" dropdown: pick the shell you like (probably /bin/sh, judging by your question).
  5. Automator will give you a sample of code, but you'll just want what you already have: transmission-remote -a "$@" (double-quotes allow correct forwarding of arguments that contain spaces).
  6. Save the app.

When Firefox runs this app to open files/downloads, it passes them in Mac's native way, then Automator translates them to shell arguments, and the shell script forwards them to transmission-remote.

share|improve this answer
    
Hi DS, thank you for answering. I did as you suggested, but it doesn't work on Mountain Lion. Here is my Automator script with "As arguments" dropdown selected: i.imgur.com/c8u6zia.png – Lionel Mar 10 '13 at 19:59
    
I've now tested that it works both on Snow Leopard, and Lion, but don't have Muntain Lion to test on. Try replacing the command with echo Hello "$@" world and testing directly in Automator. The only thing I can think of is that "Run Shell Script" action has in Options a box to "Ignore this action's input": make sure that's not accidentally checked. – DS. Mar 12 '13 at 3:45
    
I've tried the following but only blanks are sent: echo "$@" >> ~/somefile and echo "$*" >> ~/somefile with and without quotes. Perhaps it is my Firefox settings (about:config?). I'm on 19.0.2 (latest), OSX 10.8.2 in case anybody else chimes in... – Lionel Mar 12 '13 at 6:53
    
You can test without Firefox by dragging and dropping a file onto your app icon in Finder: new Firefox releases should work the same way (they do for me). You can also try testing within Automator. But sorry, no 10.8 here, so I can't check. – DS. Mar 13 '13 at 17:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .