# Ubuntu – How to run – from Firefox context menu – terminal commands selected in web pages

command lineexecute-commandfirefoxfirefox-extensions

Instead of copying it from the web and pasting it in the terminal, I want to be able to select a command displayed in a web page and with right click context menu to add it and run it in terminal.

Some Firefox addons were supposed to do this, as described here, but they do not seem to work in latest Firefox.

Are there other solutions for this?

The result should look like this

The addon you mention hasn't been updated for a while, but it is possible to run it in Firefox 17 using the hack I mention below, which I have used for other addons.

However, be very careful when using it to copy, paste, and run commands, as some forums other than this one have malicious code. However, it may be very useful for a good site like askubuntu.

Note: This method below merely edits the install file so it can be installed in the latest firefox, as xpi files are basically like zip archives, which can be manipulated.

The developer did not test it with Firefox 17, so it is unsupported, but it does seem to work. However, it will not be updated again and will receive no updates or fixes, so you must only use it on trusted sites like askubuntu.

How to edit the xpi and install it

(After writing this article myself, I noticed that a similar method for another addon was also used in this question, so the basics of the trick documented below is well known and usually works fine.)

Download the xpi file from gnome's archive:

wget "http://ftp.gnome.org/pub/mozilla.org/addons/9738/terminalrun-0.6-fx-linux.xpi"
unzip -d terminalrun terminalrun-0.6-fx-linux.xpi
cd terminalrun
gedit install.rdf


Now, just edit the Firefox version numbers in install.rdf so they look like this- choose any version of Firefox from 17 onwards to put in the MaxVersion (I chose an arbitrary number like 23.0, but you can choose a much higher one, up to 99.0.)

<em:minVersion>3.0</em:minVersion>
<em:maxVersion>23.0.*</em:maxVersion>


After saving the file, but while still in the terminalrun folder, run

zip -r terminalrun *
mv terminalrun.zip terminalrun.xpi


Now just drag the xpi file into Firefox and it will install it; restart firefox and you will be able to highlight code with your mouse and right click to open in terminal.

Usually when you highlight code it works fine (as long as the command you highlight makes sense for your system), so please test this one that gives you system information:

uname -a


Here's the firefox context menu that you should see: