summaryrefslogtreecommitdiffstats
path: root/thunderbird-open-browser.sh
blob: c9cefb4761dd8520b11b73b6d5a5563064a626b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
## Copyright (C) 2004 Warren Togami <wtogami@redhat.com>
## Contributors:   David Hill <djh[at]ii.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#
# open-browser.sh for MozillaThunderbird
# Release 5
#
# This script is called by MozillaThunderbird in order to launch the web 
# browser specified in gconf key /desktop/gnome/url-handlers/http/command
#

# Exit with Error Message
function error_exit() {
    echo "$1"
    if [ -a /usr/bin/zenity ]; then
        /usr/bin/zenity --error --text="$1"
    else
        xmessage "$1" &
    fi
    exit 1
}

# No URL specified so set to blank
url=$1
if [ -z $url ]; then
    url=about:blank
fi

# Use xdg-open if it exists (Gnome 2.6+ only)
if [ -f /usr/bin/xdg-open ]; then
    OUTPUT="$(/usr/bin/xdg-open "$url" 2>&1)"
    if [ $? -ne 0 ]; then
        error_exit "$OUTPUT"
    fi
    exit 0
fi

# Pull key from gconf, remove %s or "%s", trim leading & trailing spaces
GCONF=$(gconftool-2 -g /desktop/gnome/url-handlers/http/command 2>/dev/null | sed -e 's/%s//; s/\"\"//; s/^\ *//; s/\ *$//')
NEEDTERM=$(gconftool-2 -g /desktop/gnome/url-handlers/http/need-terminal 2>/dev/null | sed -e 's/^\ *//; s/\ *$//')

# Check if browser really exists
which $GCONF 2> /dev/null > /dev/null
if [ $? -ne 0 ]; then
    error_exit "ERROR: The browser $GCONF specified in Preferences -> Preferred Applications does not exist."
fi

# Check if text-mode browser
if [ "$NEEDTERM" == "true" ]; then
    PREFTERM=$(gconftool-2 -g /desktop/gnome/applications/terminal/exec 2>/dev/null | sed -e 's/^\ *//; s/\ *$//')
    TERMARGS=$(gconftool-2 -g /desktop/gnome/applications/terminal/exec_arg 2>/dev/null | sed -e 's/^\ *//; s/\ *$//')
    # Check if terminal exists
    which $PREFTERM 2> /dev/null > /dev/null
    if [ $? -ne 0 ]; then
        error_exit "ERROR: The terminal $GCONF specified in Preferences -> Preferred Applications does not exist."
    fi
    # Execute
    exec $PREFTERM $TERMARGS $GCONF "$url"
fi

exec $GCONF "$url"