Sunday, October 6, 2013

LXDE Default Browser shortcut link for panel

LXDE includes the "Preferred Applications" (libfm-pref-apps) program to set the preferred web browser. It works by changing the following entry:
~/.local/share/applications/mimeapps.list
[Default Applications]
x-scheme-handler/http=iceweasel.desktop
The problem with this is if you have a shortcut on the LXPanel, or Desktop, then the link is not updated automatically.  Exo-open is designed for XFCE and is ineffective to fix this issue, xdg-open cannot be used in a shortcut unless a parameter is passed - which is no good if you just want to open the browser.

A workaround is to create a new script that uses xdg-mime to query for the default http handler and create a .desktop file that runs this new script:

 sudo nano /usr/local/bin/x-www-mime-browser
#!/bin/sh

# This script uses xdg-mime to check the default browser
# and executes the .desktop from ~/.local/share/applications
# or /usr/share/applications.

URL="$1"
HANDLER=`xdg-mime query default x-scheme-handler/http`
# If handler is customized, extract from .local/... and execute
if [ -f ~/.local/share/applications/$HANDLER ]; then
    `grep Exec ~/.local/share/applications/$HANDLER \\
    | awk -F= '{ print $2 }' \\
    | awk '{ print $1 }';`
else
    `xdg-mime query default x-scheme-handler/http | awk -F. '{ print $1 }'`
fi
 sudo chmod +x /usr/local/bin/x-www-mime-browser
 sudo nano /usr/share/applications/x-www-mime-browser.desktop
[Desktop Entry]
Name=Web Browser (default)
Exec=x-www-mime-browser %u
MimeType=application/x-xdg-web-browser
Terminal=false
Type=Application
Categories=WebBrowser;Other
Icon=web-browser
NoDisplay=false
When using the LXDE Application Launch Bar Settings the "Web Browser (default)" selection will be tucked away under the "Other" category - this will prevent an extra copy visible in the "Internet" category.

No comments:

Post a Comment