Using a custom protocol handler in Firefox to run a shell script?

9,741

Found the problem

I didn't put #!/bin/bash at the top of the file. I was basically thinking of the shell script in the same way as a binary executable or something, rather than as an interpreted script, because I didn't need that line to run it directly in the terminal. I forgot that to run it from another program it has to be run through bash

So once that line is at the top of the script you can choose the shell script from firefox as the program to run your custom links with, and the link will successfully be passed into the script as the first argument.

Share:
9,741
user1092284
Author by

user1092284

Updated on September 18, 2022

Comments

  • user1092284
    user1092284 almost 2 years

    What I'd like to do is be able to start external programs from links in a local website.

    I've defined a custom protocol handler in firefox by setting the following variables in about:config

    network.protocol-handler.external.myprotocol;true
    network.protocol-handler.warn-external.myprotocol;true
    

    This successfully causes firefox to open a 'launch application' dialog box when I click on a link in the form myprotocol:///path_to_program_I_want_to_run, and then I browse to the shell script I want to use and tell firefox to run it. Unfortunately the script doesn't seem to be run at all.

    I've set the file permissions to 777 so firefox shouldn't have any trouble running it

    The shell script originally only contained the line

    $1
    

    The idea being that the path of the link would be passed in as the first argument and would immediately be run as a program. This worked fine when I ran the script myself using commands like

    #./run_program.sh gedit 
    

    or

    #./run_program.sh /home/ciaran/test_program
    

    The script now for testing purposes contains only the line

    echo "testing" > /testing/file.txt
    

    where 'testing' is a directory with 777 permissions. Also note that /testing/ actually is located at the root of my filesystem (though i can't remember why i put it there!), so I haven't just gotten mixed up between relative and absolute paths

    Again, this runs perfectly fine when I run it from the terminal, and file.txt is created in the right location. With firefox though, I am given the option to choose an application to run, I choose that shell script, and it doesn't seem to do anything. file.txt is not created at all, though there are no permission issues that I can see. So firefox just doesn't seem to be running the script.

    I have also tried changing my about:config to contain

    network.protocol-handler.expose.camara;true
    

    and

    network.protocol-handler.app.camara;path/to/shell/script
    

    with no success