18 August 2008

Use ROX-Filer to open containing folders in Firefox/Iceweasel

Update: See this for an easier way to accomplish the same goal.

One of the slightly bothersome things about using ROX-Filer with Iceweasel in Debian Etch (and I suspect Firefox in other distributions) is that Iceweasel won't "open containing folders" with ROX-Filer from Iceweasel's Downloads window. I was therefore pretty jazzed when I found this link at Rubylution that shows you how to tell Firefox (and Iceweasel) to use a specific file manager to open folders.

Of course I tried it, and of course it failed. The problem is that Firefox/Iceweasel sends the specified file manager the name of the directory in the form of a file://<filename> URL, and ROX-Filer doesn't get file URLs.* So, I wrote a script that uses sed to decode the URL to a form that ROX-Filer understands and then calls ROX-Filer with the decoded path.

So here's what you do:

Create an executable /usr/local/bin/rox-open-url:
#!/bin/bash

# Opens input argument in rox, where input argument is assumed to be a URL
# of the form file://<path-to-file>

# Mithat Konar 17 Aug 2008

# Requires sed and /usr/local/share/rox-open-url/urldecode.sed

##############################################################

# strip away file:// prefix and decode remaining characters
thePath=`echo "$1" | sed 's/^[fF][iI][lL][eE]:\/\///' | sed -f /usr/local/share/rox-open-url/urldecode.sed`

rox "$thePath"

Remember to make it executable.

Now create the file that sed will use to convert encoded characters in /usr/local/share/rox-open-url/urldecode.sed:
s/%08/\\b/g
s/%09/\\t/g
s/%0[aA]/\\n/g
s/%0[dD]/\\r/g
s/%20/\ /g
s/%21/\!/g
s/%22/\"/g
s/%23/\#/g
s/%24/\$/g
s/%25/\%/g
s/%26/\&/g
s/%27/\'/g
s/%28/\(/g
s/%29/\)/g
s/%2[aA]/\*/g
s/%2[bB]/\+/g
s/%2[cC]/\,/g
s/%2[dD]/\-/g
s/%2[eE]/\./g
s/%2[fF]/\//g
s/%30/0/g
s/%31/1/g
s/%32/2/g
s/%33/3/g
s/%34/4/g
s/%35/5/g
s/%36/6/g
s/%37/7/g
s/%38/8/g
s/%39/9/g
s/%3[aA]/\:/g
s/%3[bB]/\;/g
s/%3[cC]/\</g
s/%3[dD]/\=/g
s/%3[eE]/\>/g
s/%3[fF]/\?/g
s/%40/\@/g
s/%41/A/g
s/%42/B/g
s/%43/C/g
s/%44/D/g
s/%45/E/g
s/%46/F/g
s/%47/G/g
s/%48/H/g
s/%49/I/g
s/%4[aA]/J/g
s/%4[bB]/K/g
s/%4[cC]/L/g
s/%4[dD]/M/g
s/%4[eE]/N/g
s/%4[fF]/O/g
s/%50/P/g
s/%51/Q/g
s/%52/R/g
s/%53/S/g
s/%54/T/g
s/%55/U/g
s/%56/V/g
s/%57/W/g
s/%58/X/g
s/%59/Y/g
s/%5[aA]/Z/g
s/%5[bB]/\[/g
s/%5[cC]/\\/g
s/%5[dD]/\]/g
s/%5[eE]/\^/g
s/%5[fF]/\_/g
s/%60/\`/g
s/%61/a/g
s/%62/b/g
s/%63/c/g
s/%64/d/g
s/%65/e/g
s/%66/f/g
s/%67/g/g
s/%68/h/g
s/%69/i/g
s/%6[aA]/j/g
s/%6[bB]/k/g
s/%6[cC]/l/g
s/%6[dD]/m/g
s/%6[eE]/n/g
s/%6[fF]/o/g
s/%70/p/g
s/%71/q/g
s/%72/r/g
s/%73/s/g
s/%74/t/g
s/%75/u/g
s/%76/v/g
s/%77/w/g
s/%78/x/g
s/%79/y/g
s/%7[aA]/\z/g
s/%7[bB]/\{/g
s/%7[cC]/\|/g
s/%7[dD]/\}/g
s/%7[eE]/\~/g

Once you've done this, you can use the method described at Rubylution to set rox-open-url as the command to use to open containing folders.

Caveats: The script and sed file should be considered beta. I have done my best to make sure that the files render properly in HTML, but conversion gremlins may exist. If you find any problems, please let me know.

Reinventing the wheel? Probably. I'm pretty sure someone else has already done something very similar to this, or there may be an easier way to do the same thing. But in the two minutes I spent trying, I wasn't able to find anything.

*This is true at least in Firefox 2 and the version of ROX-Filer that's part of Debian Etch. I don't know what Firefox 3 does nor if the latest release of ROX-Filer handles file URLs.

5 comments:

jayjaygibbs said...

Cool. Thanks for that. Works perfectly. That has been bugging me for ages!!

XORwell said...

Thank you very much! Just what i needed. Works like a charm.

Alex Yeh said...

rox already has a uri-parsing feature. Simply create a shellscript that goes like:
#!/bin/sh exec /usr/bin/rox -U "$@"

and you are done. No need for all this extra complexity.

Mithat said...

@Alex: You missed the update at the top of the post. It links to http://lovingthepenguin.blogspot.com/2009/09/use-rox-filer-to-open-containing.html, which describes your solution. The problem was that in 2008 in Etch this option wasn't available.

bruno caillier said...

Great !!!
2016 very use full

now
xdg-open /home/bruno/
works

thks