2 #---------------------------------------------
5 # Utility script to get various settings from the desktop environment.
7 # Refer to the usage() function below for usage.
9 # Copyright 2009, Google Inc.
13 # Permission is hereby granted, free of charge, to any person obtaining a
14 # copy of this software and associated documentation files (the "Software"),
15 # to deal in the Software without restriction, including without limitation
16 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 # and/or sell copies of the Software, and to permit persons to whom the
18 # Software is furnished to do so, subject to the following conditions:
20 # The above copyright notice and this permission notice shall be included
21 # in all copies or substantial portions of the Software.
23 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
27 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 # OTHER DEALINGS IN THE SOFTWARE.
31 #---------------------------------------------
38 xdg-settings - get various settings from the desktop environment
42 xdg-settings { get | check | set } {property} [subproperty] [value]
44 xdg-settings { --help | --list | --manual | --version }
48 xdg-settings gets various settings from the desktop environment. For instance,
49 desktop environments often provide proxy configuration and default web browser
50 settings. Using xdg-settings these parameters can be extracted for use by
51 applications that do not use the desktop environment's libraries (which would
52 use the settings natively).
54 xdg-settings is for use inside a desktop session only. It is not recommended to
55 use xdg-settings as root.
60 Show command synopsis.
62 List all properties xdg-settings knows about.
66 Show the xdg-utils version information.
70 When using xdg-settings to get, check or set a destkop setting, properties and
71 possibly sub-properties are used to specify the setting to be changed.
73 Some properties (such as default-web-browser) fully describe the setting to be
74 changed. Other properties (such as default-url-scheme-handler) require more
75 information (in this case the actual scheme to set the default handler for)
76 which must be provided in a sub-property.
80 An exit code of 0 indicates success while a non-zero exit code indicates
81 failure. The following failure codes can be returned:
84 Error in command line syntax.
86 One of the files passed on the command line did not exist.
88 A required tool could not be found.
94 Get the desktop file name of the current default web browser
96 xdg-settings get default-web-browser
99 Check whether the default web browser is firefox.desktop, which can be false
100 even if "get default-web-browser" says that is the current value (if only some
101 of the underlying settings actually reflect that value)
103 xdg-settings check default-web-browser firefox.desktop
106 Set the default web browser to google-chrome.desktop
108 xdg-settings set default-web-browser google-chrome.desktop
111 Set the default mailto URL scheme handler to be evolution.desktop
113 xdg-settings set default-url-scheme-handler mailto evolution.desktop
122 xdg-settings - get various settings from the desktop environment
126 xdg-settings { get | check | set } {property} [subproperty] [value]
128 xdg-settings { --help | --list | --manual | --version }
135 #----------------------------------------------------------------------------
136 # Common utility functions included in all XDG wrapper scripts
137 #----------------------------------------------------------------------------
141 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0;
142 [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0;
147 # This handles backslashes but not quote marks.
154 #-------------------------------------------------------------
155 # map a binary to a .desktop file
156 binary_to_desktop_file()
158 search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
159 binary="`which "$1"`"
160 binary="`readlink -f "$binary"`"
161 base="`basename "$binary"`"
163 for dir in $search; do
165 [ "$dir" ] || continue
166 [ -d "$dir/applications" -o -d "$dir/applnk" ] || continue
167 for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.desktop "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do
168 [ -r "$file" ] || continue
169 # Check to make sure it's worth the processing.
170 grep -q "^Exec.*$base" "$file" || continue
171 # Make sure it's a visible desktop file (e.g. not "preferred-web-browser.desktop").
172 grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue
173 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
174 command="`which "$command"`"
175 if [ x"`readlink -f "$command"`" = x"$binary" ]; then
176 # Fix any double slashes that got added path composition
177 echo "$file" | sed -e 's,//*,/,g'
184 #-------------------------------------------------------------
185 # map a .desktop file to a binary
186 ## FIXME: handle vendor dir case
187 desktop_file_to_binary()
189 search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
190 desktop="`basename "$1"`"
192 for dir in $search; do
194 [ "$dir" -a -d "$dir/applications" ] || continue
195 file="$dir/applications/$desktop"
196 [ -r "$file" ] || continue
197 # Remove any arguments (%F, %f, %U, %u, etc.).
198 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
199 command="`which "$command"`"
200 readlink -f "$command"
205 #-------------------------------------------------------------
206 # Exit script on successfully completing the desired operation
210 if [ $# -gt 0 ]; then
219 #-----------------------------------------
220 # Exit script on malformed arguments, not enough arguments
221 # or missing required option.
222 # prints usage information
224 exit_failure_syntax()
226 if [ $# -gt 0 ]; then
227 echo "xdg-settings: $@" >&2
228 echo "Try 'xdg-settings --help' for more information." >&2
231 echo "Use 'man xdg-settings' or 'xdg-settings --manual' for additional info."
237 #-------------------------------------------------------------
238 # Exit script on missing file specified on command line
240 exit_failure_file_missing()
242 if [ $# -gt 0 ]; then
243 echo "xdg-settings: $@" >&2
249 #-------------------------------------------------------------
250 # Exit script on failure to locate necessary tool applications
252 exit_failure_operation_impossible()
254 if [ $# -gt 0 ]; then
255 echo "xdg-settings: $@" >&2
261 #-------------------------------------------------------------
262 # Exit script on failure returned by a tool application
264 exit_failure_operation_failed()
266 if [ $# -gt 0 ]; then
267 echo "xdg-settings: $@" >&2
273 #------------------------------------------------------------
274 # Exit script on insufficient permission to read a specified file
276 exit_failure_file_permission_read()
278 if [ $# -gt 0 ]; then
279 echo "xdg-settings: $@" >&2
285 #------------------------------------------------------------
286 # Exit script on insufficient permission to write a specified file
288 exit_failure_file_permission_write()
290 if [ $# -gt 0 ]; then
291 echo "xdg-settings: $@" >&2
299 if [ ! -e "$1" ]; then
300 exit_failure_file_missing "file '$1' does not exist"
302 if [ ! -r "$1" ]; then
303 exit_failure_file_permission_read "no permission to read file '$1'"
307 check_vendor_prefix()
310 [ -n "$file_label" ] || file_label="filename"
318 echo "xdg-settings: $file_label '$file' does not have a proper vendor prefix" >&2
319 echo 'A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated' >&2
320 echo 'with a dash ("-"). An example '"$file_label"' is '"'example-$file'" >&2
321 echo "Use --novendor to override or 'xdg-settings --manual' for additional info." >&2
327 # if the file exists, check if it is writeable
328 # if it does not exists, check if we are allowed to write on the directory
330 if [ ! -w "$1" ]; then
331 exit_failure_file_permission_write "no permission to write to file '$1'"
335 if [ ! -w "$DIR" -o ! -x "$DIR" ]; then
336 exit_failure_file_permission_write "no permission to create file '$1'"
341 #----------------------------------------
342 # Checks for shared commands, e.g. --help
344 check_common_commands()
346 while [ $# -gt 0 ] ; do
353 echo "Use 'man xdg-settings' or 'xdg-settings --manual' for additional info."
363 echo "xdg-settings 1.1.0 rc1"
370 check_common_commands "$@"
372 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL;
373 if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then
375 xdg_redirect_output=" > /dev/null 2> /dev/null"
377 # All output to stderr
378 xdg_redirect_output=" >&2"
381 #--------------------------------------
382 # Checks for known desktop environments
383 # set variable DE to the desktop environments name, lowercase
387 # see https://bugs.freedesktop.org/show_bug.cgi?id=34164
390 if [ -n "${XDG_CURRENT_DESKTOP}" ]; then
391 case "${XDG_CURRENT_DESKTOP}" in
406 if [ x"$DE" = x"" ]; then
408 if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
409 elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
410 elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
411 elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
412 elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
416 if [ x"$DE" = x"" ]; then
417 # fallback to checking $DESKTOP_SESSION
418 case "$DESKTOP_SESSION" in
431 if [ x"$DE" = x"" ]; then
432 # fallback to uname output for other platforms
433 case "$(uname 2>/dev/null)" in
440 if [ x"$DE" = x"gnome" ]; then
441 # gnome-default-applications-properties is only available in GNOME 2.x
442 # but not in GNOME 3.x
443 which gnome-default-applications-properties > /dev/null 2>&1 || DE="gnome3"
447 #----------------------------------------------------------------------------
448 # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4
449 # It also always returns 1 in KDE 3.4 and earlier
450 # Simply return 0 in such case
452 kfmclient_fix_exit_code()
454 version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
455 major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
456 minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
457 release=`echo $version | sed 's/KDE.*: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'`
458 test "$major" -gt 3 && return $1
459 test "$minor" -gt 5 && return $1
460 test "$release" -gt 4 && return $1
464 check_desktop_filename()
468 exit_failure_syntax "invalid application name"
474 exit_failure_syntax "invalid application name"
479 # {{{ default browser
480 # {{{ utility functions
482 # In order to remove an application from the automatically-generated list of
483 # applications for handling a given MIME type, the desktop environment may copy
484 # the global .desktop file into the user's .local directory, and remove that
485 # MIME type from its list. In that case, we must restore the MIME type to the
486 # application's list of MIME types before we can set it as the default for that
487 # MIME type. (We can't just delete the local version, since the user may have
488 # made other changes to it as well. So, tweak the existing file.)
489 # This function is hard-coded for text/html but it could be adapted if needed.
490 fix_local_desktop_file()
492 if test -z "$2" ; then
497 apps="${XDG_DATA_HOME:-$HOME/.local/share}/applications"
498 # No local desktop file?
499 [ ! -f "$apps/$1" ] && return
500 MIMETYPES="`grep "^MimeType=" "$apps/$1" | cut -d= -f 2-`"
502 $MIME\;*|*\;$MIME\;*|*\;$MIME\;|*\;$MIME)
503 # Already has the mime-type? Great!
508 # Add the mime-type to the list
509 temp="`mktemp "$apps/$1.XXXXXX"`" || return
510 grep -v "^MimeType=" "$apps/$1" >> "$temp"
511 echo "MimeType=$MIME;$MIMETYPES" >> "$temp"
513 oldlines="`wc -l < "$apps/$1"`"
514 newlines="`wc -l < "$temp"`"
515 # The new file should have at least as many lines as the old.
516 if [ $oldlines -le $newlines ]; then
517 mv "$temp" "$apps/$1"
518 # This can take a little bit to get noticed.
526 # }}} utility functions
531 # xdg-mime may use ktradertest, which will fork off a copy of kdeinit if
532 # one does not already exist. It will exit after about 15 seconds if no
533 # further processes need it around. But since it does not close its stdout,
534 # the shell (via grep) will wait around for kdeinit to exit. If we start a
535 # copy here, that copy will be used in xdg-mime and we will avoid waiting.
536 if [ "$DE" = kde -a -z "$XDG_MIME_FIXED" ]; then
537 ktradertest text/html Application > /dev/null 2>&1
538 # Only do this once, as we only need it once.
545 if test -z "$1" ; then
551 xdg-mime query default "$MIME"
557 if test -z "$2" ; then
562 orig="`get_browser_mime $MIME`"
563 # Fixing the local desktop file can actually change the default browser all
564 # by itself, so we fix it only after querying to find the current default.
565 fix_local_desktop_file "$1" "$MIME" || return
566 mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/applications"
567 xdg-mime default "$1" "$MIME" || return
568 if [ x"`get_browser_mime`" != x"$1" ]; then
569 # Put back the original value
570 xdg-mime default "$orig" "$MIME"
571 exit_failure_operation_failed
578 # Reads the KDE configuration setting, compensating for a bug in some versions of kreadconfig.
584 application="`kreadconfig --file $configfile --group $configsection --key $configkey`"
585 if [ x"$application" != x ]; then
588 # kreadconfig in KDE 4 may not notice Key[$*]=... localized settings, so
589 # check by hand if it didn't find anything (oddly kwriteconfig works
591 configfile_dir=`kde${KDE_SESSION_VERSION}-config --path config | cut -d ':' -f 1`
592 configfile_path="$configfile_dir/$configfile"
593 [ ! -f "$configfile_path" ] && return
594 # This will only take the first value if there is more than one.
595 grep "^$configkey"'\[$[^]=]*\]=' "$configfile_path" | head -n 1 | cut -d= -f 2-
602 # Resolves the KDE browser setting to a binary: if prefixed with !, simply removes it;
603 # otherwise, uses desktop_file_to_binary to get the binary out of the desktop file.
604 resolve_kde_browser()
606 [ -z "$browser" ] && return
612 desktop_file_to_binary "$browser"
617 # Does the opposite of resolve_kde_browser: if prefixed with !, tries to find a desktop
618 # file corresponding to the binary, otherwise just returns the desktop file name.
619 resolve_kde_browser_desktop()
621 [ -z "$browser" ] && return
624 desktop="`binary_to_desktop_file "${browser#!}"`"
635 read_kde_config kdeglobals General BrowserApplication
640 browser="`read_kde_browser`"
641 if [ x"$browser" = x ]; then
642 # No explicit default browser; KDE will use the MIME type text/html.
645 resolve_kde_browser_desktop
651 check="`desktop_file_to_binary "$1"`"
652 if [ -z "$check" ]; then
656 browser="`read_kde_browser`"
657 binary="`resolve_kde_browser`"
658 # Because KDE will use the handler for MIME type text/html if this value
659 # is empty, we allow either the empty string or a match to $check here.
660 if [ x"$binary" != x -a x"$binary" != x"$check" ]; then
664 browser="`get_browser_mime`"
665 binary="`desktop_file_to_binary "$browser"`"
666 if [ x"$binary" != x"$check" ]; then
676 set_browser_mime "$1" || return
677 kwriteconfig --file kdeglobals --group General --key BrowserApplication "$1"
685 binary="`gconftool-2 --get /desktop/gnome/applications/browser/exec | first_word`"
686 if [ x"$binary" = x ]; then
687 # No default browser; GNOME might use the MIME type text/html.
690 # gconftool gives the binary (maybe with %s etc. afterward),
691 # but we want the desktop file name, not the binary. So, we
692 # have to find the desktop file to which it corresponds.
693 desktop="`binary_to_desktop_file "$binary"`"
698 check_browser_gnome()
700 check="`desktop_file_to_binary "$1"`"
701 if [ -z "$check" ]; then
705 binary="`gconftool-2 --get /desktop/gnome/applications/browser/exec | first_word`"
706 if [ x"$binary" != x"$check" ]; then
710 # Check HTTP and HTTPS, but not about: and unknown:.
711 for protocol in http https; do
712 binary="`gconftool-2 --get /desktop/gnome/url-handlers/$protocol/command | first_word`"
713 if [ x"$binary" != x"$check" ]; then
718 browser="`get_browser_mime`"
719 binary="`desktop_file_to_binary "$browser"`"
720 if [ x"$binary" != x"$check" ]; then
730 binary="`desktop_file_to_binary "$1"`"
731 [ "$binary" ] || exit_failure_file_missing
732 set_browser_mime "$1" || return
734 # Set the default browser.
735 gconftool-2 --type string --set /desktop/gnome/applications/browser/exec "$binary"
736 gconftool-2 --type bool --set /desktop/gnome/applications/browser/needs_term false
737 gconftool-2 --type bool --set /desktop/gnome/applications/browser/nremote true
738 # Set the handler for HTTP and HTTPS.
739 for protocol in http https; do
740 gconftool-2 --type string --set /desktop/gnome/url-handlers/$protocol/command "$binary %s"
741 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$protocol/needs_terminal false
742 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$protocol/enabled true
744 # Set the handler for about: and unknown URL types.
745 for protocol in about unknown; do
746 gconftool-2 --type string --set /desktop/gnome/url-handlers/$protocol/command "$binary %s"
755 get_browser_mime "x-scheme-handler/http"
758 check_browser_gnome3()
761 check="`desktop_file_to_binary "$1"`"
762 if [ -z "$check" ]; then
766 # Check HTTP and HTTPS, but not about: and unknown:.
767 for protocol in http https; do
768 browser="`get_browser_mime "x-scheme-handler/$protocol"`"
769 if [ x"$browser" != x"$desktop" ]; then
780 binary="`desktop_file_to_binary "$1"`"
781 [ "$binary" ] || exit_failure_file_missing
782 set_browser_mime "$1" || return
784 # Set the default browser.
785 for protocol in http https about unknown; do
786 set_browser_mime "$1" "x-scheme-handler/$protocol" || return
794 search="${XDG_CONFIG_HOME:-$HOME/.config}:${XDG_CONFIG_DIRS:-/etc/xdg}"
796 for dir in $search; do
798 [ "$dir" -a -d "$dir/xfce4" ] || continue
799 file="$dir/xfce4/helpers.rc"
800 [ -r "$file" ] || continue
801 grep -q "^WebBrowser=" "$file" || continue
802 desktop="`grep "^WebBrowser=" "$file" | cut -d= -f 2-`"
803 echo "$desktop.desktop"
806 exit_failure_operation_failed
811 browser="`get_browser_xfce`"
812 if [ x"$browser" != x"$1" ]; then
820 check_xfce_desktop_file()
822 # Annoyingly, xfce wants its .desktop files in a separate directory instead
823 # of the standard locations, and requires a few custom tweaks to them:
824 # "Type" must be "X-XFCE-Helper"
825 # "X-XFCE-Category" must be "WebBrowser" (for web browsers, anyway)
826 # "X-XFCE-Commands" and "X-XFCE-CommandsWithParameter" must be set
827 search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
829 for dir in $search; do
831 [ "$dir" -a -d "$dir/xfce4/helpers" ] || continue
832 file="$dir/xfce4/helpers/$1"
833 # We have the file, no need to create it.
834 [ -r "$file" ] && return
837 for dir in $search; do
839 [ "$dir" -a -d "$dir/applications" ] || continue
840 file="$dir/applications/$1"
841 if [ -r "$file" ]; then
842 # Found a file to convert.
843 target="${XDG_DATA_HOME:-$HOME/.local/share}/xfce4/helpers"
845 grep -v "^Type=" "$file" > "$target/$1"
846 echo "Type=X-XFCE-Helper" >> "$target/$1"
847 echo "X-XFCE-Category=WebBrowser" >> "$target/$1"
848 # Change %F, %f, %U, and %u to "%s".
849 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | sed -e 's/%[FfUu]/"%s"/g'`"
850 echo "X-XFCE-Commands=`echo "$command" | first_word`" >> "$target/$1"
851 echo "X-XFCE-CommandsWithParameter=$command" >> "$target/$1"
860 check_xfce_desktop_file "$1" || exit_failure_operation_failed
862 helper_dir="${XDG_CONFIG_HOME:-$HOME/.config}/xfce4"
863 if [ ! -d "$helper_dir" ]; then
864 mkdir -p "$helper_dir" || exit_failure_operation_failed
867 helpers_rc="$helper_dir/helpers.rc"
868 # Create the file if it does not exist to avoid special cases below.
869 if [ ! -r "$helpers_rc" ]; then
870 touch "$helpers_rc" || exit_failure_operation_failed
873 temp="`mktemp "$helpers_rc.XXXXXX"`" || return
874 grep -v "^WebBrowser=" "$helpers_rc" >> "$temp"
875 echo "WebBrowser=${1%.desktop}" >> "$temp"
877 oldlines="`wc -l < "$helpers_rc"`"
878 newlines="`wc -l < "$temp"`"
879 # The new file should have at least as many lines as the old.
880 if [ $oldlines -le $newlines ]; then
881 mv "$temp" "$helpers_rc"
889 # }}} default browser
891 # {{{ default url scheme handler
893 exit_unimplemented_default_handler()
895 exit_failure_operation_impossible "default-url-scheme-handler not implemented for $DE"
900 # Recent versions of KDE support default scheme handler applications using the
901 # mime type of x-scheme-handler/scheme. Older versions will not support this
902 # but do have support for setting a default mail handler. There is also a
903 # system in KDE where .protocol files can be used, however this is not
904 # supported by this script. When reading a scheme handler we will use the
905 # default mail handler for the mailto scheme, otherwise we will use the mime
906 # type x-scheme-handler/scheme.
908 get_url_scheme_handler_kde()
910 if [ "$1" = "mailto" ]; then
911 handler="`read_kde_config emaildefaults PROFILE_Default EmailClient | first_word`"
912 echo "handler is $handler"
913 if [ x"$handler" != x ]; then
914 binary_to_desktop_file "$handler"
916 get_browser_mime "x-scheme-handler/$1"
919 get_browser_mime "x-scheme-handler/$1"
923 check_url_scheme_handler_kde()
925 check="`desktop_file_to_binary "$2"`"
926 if [ -z "$check" ]; then
930 if [ x"$1" = "mailto" ]; then
931 binary="`read_kde_config emaildefaults PROFILE_Default EmailClient`"
932 if [ x"$binary" != x"$check" ]; then
937 handler="`get_browser_mime x-scheme-handler/$1`"
938 binary="`desktop_file_to_binary "$handler"`"
939 if [ x"$binary" != x"$check" ]; then
947 set_url_scheme_handler_kde()
949 set_browser_mime "$2" "x-scheme-handler/$1" || return
950 if [ "$1" = "mailto" ]; then
951 binary="`desktop_file_to_binary "$2"`"
952 kwriteconfig --file emaildefaults --group PROFILE_Default --key EmailClient "$binary"
959 get_url_scheme_handler_gnome()
961 binary="`gconftool-2 --get /desktop/gnome/url-handlers/$1/command | first_word`"
962 if [ x"$binary" != x"" ]; then
963 # gconftool gives the binary (maybe with %s etc. afterward),
964 # but we want the desktop file name, not the binary. So, we
965 # have to find the desktop file to which it corresponds.
966 desktop="`binary_to_desktop_file "$binary"`"
971 check_url_scheme_handler_gnome()
973 check="`desktop_file_to_binary "$2"`"
974 if [ -z "$check" ]; then
978 binary="`gconftool-2 --get /desktop/gnome/url-handlers/$1/command | first_word`"
979 if [ x"$binary" != x"$check" ]; then
987 set_url_scheme_handler_gnome()
989 binary="`desktop_file_to_binary "$2"`"
990 [ "$binary" ] || exit_failure_file_missing
992 gconftool-2 --type string --set /desktop/gnome/url-handlers/$1/command "$binary %s"
993 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$1/needs_terminal false
994 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$1/enabled true
1000 get_url_scheme_handler_gnome3()
1002 get_browser_mime "x-scheme-handler/$1"
1005 check_url_scheme_handler_gnome3()
1008 check="`desktop_file_to_binary "$2"`"
1009 if [ -z "$check" ]; then
1013 browser="`get_browser_mime "x-scheme-handler/$1"`"
1014 if [ x"$browser" != x"$desktop" ]; then
1022 set_url_scheme_handler_gnome3()
1024 binary="`desktop_file_to_binary "$2"`"
1025 [ "$binary" ] || exit_failure_file_missing
1026 set_browser_mime "$2" || return
1028 # Set the default browser.
1029 set_browser_mime "$2" "x-scheme-handler/$1" || return
1035 get_url_scheme_handler_xfce()
1037 exit_unimplemented_default_handler "$1"
1040 check_url_scheme_handler_xfce()
1042 exit_unimplemented_default_handler "$1"
1045 set_url_scheme_handler_xfce()
1047 exit_unimplemented_default_handler "$1"
1051 # }}} default protocol handler
1055 # The PROP comments in this function are used to generate the output of
1056 # the --list option. The formatting is important. Make sure to line up the
1057 # property descriptions with spaces so that it will look nice.
1058 if [ x"$op" = x"get" ]; then
1060 default-web-browser) # PROP: Default web browser
1064 default-url-scheme-handler) # PROP: Default handler for URL scheme
1065 get_url_scheme_handler_$DE "$1"
1072 elif [ x"$op" = x"check" ]; then
1074 default-web-browser)
1075 check_desktop_filename "$1"
1076 check_browser_$DE "$1"
1079 default-url-scheme-handler)
1080 check_desktop_filename "$2"
1081 check_url_scheme_handler_$DE "$1" "$2"
1090 default-web-browser)
1091 [ $# -eq 1 ] || exit_failure_syntax "unexpected/missing argument"
1092 check_desktop_filename "$1"
1093 set_browser_$DE "$1"
1096 default-url-scheme-handler)
1097 [ $# -eq 2 ] || exit_failure_syntax "unexpected/missing argument"
1098 check_desktop_filename "$2"
1099 set_url_scheme_handler_$DE "$1" "$2"
1108 if [ $? -eq 0 ]; then
1111 exit_failure_operation_failed
1117 # We only know how to get or check the default web browser.
1118 [ x"$op" != x"get" -a x"$op" != x"check" ] && exit_failure_operation_impossible
1119 [ x"$parm" != x"default-web-browser" ] && exit_failure_operation_impossible
1121 # First look in $BROWSER
1122 if [ x"$BROWSER" != x ]; then
1123 binary="`which "${BROWSER%%:*}"`"
1125 # Debian and Ubuntu (and others?) have x-www-browser.
1126 binary="`which x-www-browser`"
1129 [ "$binary" ] || exit_failure_operation_failed
1131 binary="`readlink -f "$binary"`"
1133 [ "$binary" ] || exit_failure_operation_failed
1135 if [ x"$op" = x"get" ]; then
1136 desktop="`binary_to_desktop_file "$binary"`"
1140 check="`desktop_file_to_binary "$1"`"
1141 if [ -z "$check" ]; then
1145 if [ x"$binary" != x"$check" ]; then
1154 if [ x"$1" = x"--list" ]; then
1155 echo "Known properties:"
1156 # Extract the property names from dispatch_specific() above.
1157 grep "^[ ]*[^)]*) # PROP:" "$0" | sed -e 's/^[ ]*\([^)]*\)) # PROP: \(.*\)$/ \1 \2/' | sort
1161 [ x"$1" != x ] || exit_failure_syntax "no operation given"
1162 [ x"$2" != x ] || exit_failure_syntax "no parameter name given"
1163 [ x"$1" = x"get" -o x"$3" != x ] || exit_failure_syntax "no parameter value given"
1169 if [ x"$op" != x"get" -a x"$op" != x"check" -a x"$op" != x"set" ]; then
1170 exit_failure_syntax "invalid operation"
1177 dispatch_specific "$@"
1181 dispatch_generic "$@"
1185 exit_failure_operation_impossible "unknown desktop environment"