PDA

View Full Version : Bash: Detecting default file browser



Jesdisciple
April 15th, 2009, 03:11 AM
I have a Bash script which, at the end, opens a directory in Nautilus. I think my script may be useful to others, so I'm wondering how I can tell whether the user prefers Konqueror or what not? I'm pretty sure there must be an env var or something...

Thanks. :)

cszikszoy
April 15th, 2009, 03:47 AM
you could just use

$ xdg-opn <path>
and the path will open in whatever file browser the user uses, be it konquerer, nautilus, or anything else.

kerry_s
April 15th, 2009, 05:40 AM
$ xdg-open <path>

cszikszoy
April 15th, 2009, 08:40 AM
$ xdg-open <path>

Right, oops! Typos :mad:

kerry_s
April 15th, 2009, 09:29 AM
Right, oops! Typos :mad:

:lolflag: happens to me all the time, damn that fat finger syndrome! ;)

Jesdisciple
April 15th, 2009, 02:05 PM
Thanks to both of you!

Jesdisciple
April 15th, 2009, 03:46 PM
Oops... I thought it worked and then stopped working when I sudo'ed the script (http://ubuntuforums.org/showthread.php?p=7076521), but it actually gives this error regardless of privileges:
Warning: unknown mime-type for "gnome-pilot/new" -- using "application/octet-stream"
Error: no "view" mailcap rules found for type "application/octet-stream"

Does anyone know why? Thanks.

Jesdisciple
April 15th, 2009, 09:53 PM
And... I was right the first time. There's no problem if the script is not executed as root. Still, does anyone happen to know why?

Reiger
April 15th, 2009, 11:38 PM
Knowing? No.

Still, you may be able to make progress from observing the output of the following:


cd ~/.gnome2
ls -A
cd /root
sudo su
cd .gnome2
ls -A

Jesdisciple
April 16th, 2009, 12:19 AM
The only significant difference I see is nautilus-sendto, but its manpage is a disappointment.
cd ~/.gnome2
chris@Jesdisciple-laptop:~/.gnome2$ ls -A
accels backgrounds.xml epiphany gedit glchess gnome-sudoku gok main panel2.d yelp
accelsevince deskbar-applet evince gedit-2 gnomemeeting gnometris.d iagno nautilus-scripts rhythmbox
accelsgedit eog file-roller gedit-metadata.xml gnome-power-manager gnome-volume-control keyrings nautilus-sendto share
chris@Jesdisciple-laptop:~/.gnome2$ cd /root
chris@Jesdisciple-laptop:/root$ sudo su
[sudo] password for chris:
root@Jesdisciple-laptop:~# cd .gnome2
root@Jesdisciple-laptop:~/.gnome2# ls -A
accels accelsgedit file-roller gedit-2 gedit-metadata.xml main nautilus-scripts network-admin-locations yelp

Thanks bunches.

Reiger
April 16th, 2009, 12:32 AM
This is mine:


accels backgrounds.xml file-roller gedit-metadata.xml keyrings nautilus-scripts rhythmbox
accelsevince eog f-spot gnome-pilot.d main network-admin-locations share
accelsgedit evince gedit-2 gnome-power-manager meld panel2.d yelp


On Jaunty, upgraded from Intrepid which was in turn upgraded from Hardy. Atlough I have stripped Gnome (because I run KDE as my main DE, and I have no need for Gnome stuff interfering with my KDE).

Jesdisciple
April 16th, 2009, 02:38 AM
Here's something: I've determined that the issue comes from the combination of sudo and xdg-open, regardless of all other factors.

I don't get the error if I:
run the command directly without sudo
run the command without sudo from a script run without sudo


I do get the error if I:
run the command directly with sudo
run the command directly with sudo -u chris
run the command with sudo from a script run without sudo
run the command without sudo from a script run with sudo
run the command with sudo from a script run with sudo
run the command with sudo -u chris from a script run with sudo
run the command with sudo -u chris from a script run without sudo

Jesdisciple
April 16th, 2009, 04:35 PM
I've filed Bug #362121 (https://bugs.launchpad.net/ubuntu/+source/xdg-utils/+bug/362121) for this.