| OLD | NEW |
| 1 #!/bin/sh | 1 #!/bin/sh |
| 2 #--------------------------------------------- | 2 #--------------------------------------------- |
| 3 # xdg-settings | 3 # xdg-settings |
| 4 # | 4 # |
| 5 # Utility script to get various settings from the desktop environment. | 5 # Utility script to get various settings from the desktop environment. |
| 6 # | 6 # |
| 7 # Refer to the usage() function below for usage. | 7 # Refer to the usage() function below for usage. |
| 8 # | 8 # |
| 9 # Copyright 2009, Google Inc. | 9 # Copyright 2009, Google Inc. |
| 10 # | 10 # |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | 28 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 29 # OTHER DEALINGS IN THE SOFTWARE. | 29 # OTHER DEALINGS IN THE SOFTWARE. |
| 30 # | 30 # |
| 31 #--------------------------------------------- | 31 #--------------------------------------------- |
| 32 | 32 |
| 33 manualpage() | 33 manualpage() |
| 34 { | 34 { |
| 35 cat << _MANUALPAGE | 35 cat << _MANUALPAGE |
| 36 Name | 36 Name |
| 37 | 37 |
| 38 xdg-settings - get various settings from the desktop environment | 38 xdg-settings - get various settings from the desktop |
| 39 environment |
| 39 | 40 |
| 40 Synopsis | 41 Synopsis |
| 41 | 42 |
| 42 xdg-settings { get | check | set } {property} [value] | 43 xdg-settings { get | check | set } {property} [subproperty] |
| 44 [value] |
| 43 | 45 |
| 44 xdg-settings { --help | --list | --manual | --version } | 46 xdg-settings { --help | --list | --manual | --version } |
| 45 | 47 |
| 46 Description | 48 Description |
| 47 | 49 |
| 48 xdg-settings gets various settings from the desktop environment. For instance, | 50 xdg-settings gets various settings from the desktop |
| 49 desktop environments often provide proxy configuration and default web browser | 51 environment. For instance, desktop environments often provide |
| 50 settings. Using xdg-settings these parameters can be extracted for use by | 52 proxy configuration and default web browser settings. Using |
| 51 applications that do not use the desktop environment's libraries (which would | 53 xdg-settings these parameters can be extracted for use by |
| 52 use the settings natively). | 54 applications that do not use the desktop environment's |
| 55 libraries (which would use the settings natively). |
| 53 | 56 |
| 54 xdg-settings is for use inside a desktop session only. It is not recommended to | 57 xdg-settings is for use inside a desktop session only. It is |
| 55 use xdg-settings as root. | 58 not recommended to use xdg-settings as root. |
| 56 | 59 |
| 57 Options | 60 Options |
| 58 | 61 |
| 59 --help | 62 --help |
| 60 Show command synopsis. | 63 Show command synopsis. |
| 61 --list | 64 |
| 62 List all properties xdg-settings knows about. | 65 --list |
| 63 --manual | 66 List all properties xdg-settings knows about. |
| 64 Show this manualpage. | 67 |
| 65 --version | 68 --manual |
| 66 Show the xdg-utils version information. | 69 Show this manualpage. |
| 70 |
| 71 --version |
| 72 Show the xdg-utils version information. |
| 73 |
| 74 Properties |
| 75 |
| 76 When using xdg-settings to get, check or set a destkop setting, |
| 77 properties and possibly sub-properties are used to specify the |
| 78 setting to be changed. |
| 79 |
| 80 Some properties (such as default-web-browser) fully describe |
| 81 the setting to be changed. Other properties (such as |
| 82 default-url-scheme-handler) require more information (in this |
| 83 case the actual scheme to set the default handler for) which |
| 84 must be provided in a sub-property. |
| 67 | 85 |
| 68 Exit Codes | 86 Exit Codes |
| 69 | 87 |
| 70 An exit code of 0 indicates success while a non-zero exit code indicates | 88 An exit code of 0 indicates success while a non-zero exit code |
| 71 failure. The following failure codes can be returned: | 89 indicates failure. The following failure codes can be returned: |
| 72 | 90 |
| 73 1 | 91 1 |
| 74 Error in command line syntax. | 92 Error in command line syntax. |
| 75 2 | 93 |
| 76 One of the files passed on the command line did not exist. | 94 2 |
| 77 3 | 95 One of the files passed on the command line did not |
| 78 A required tool could not be found. | 96 exist. |
| 79 4 | 97 |
| 80 The action failed. | 98 3 |
| 99 A required tool could not be found. |
| 100 |
| 101 4 |
| 102 The action failed. |
| 81 | 103 |
| 82 Examples | 104 Examples |
| 83 | 105 |
| 84 Get the desktop file name of the current default web browser | 106 Get the desktop file name of the current default web browser |
| 85 | |
| 86 xdg-settings get default-web-browser | 107 xdg-settings get default-web-browser |
| 87 | 108 |
| 88 | 109 Check whether the default web browser is firefox.desktop, which |
| 89 Check whether the default web browser is firefox.desktop, which can be false | 110 can be false even if "get default-web-browser" says that is the |
| 90 even if "get default-web-browser" says that is the current value (if only some | 111 current value (if only some of the underlying settings actually |
| 91 of the underlying settings actually reflect that value) | 112 reflect that value) |
| 92 | |
| 93 xdg-settings check default-web-browser firefox.desktop | 113 xdg-settings check default-web-browser firefox.desktop |
| 94 | 114 |
| 95 | 115 Set the default web browser to google-chrome.desktop |
| 96 Set the default web browser to google-chrome.desktop | |
| 97 | |
| 98 xdg-settings set default-web-browser google-chrome.desktop | 116 xdg-settings set default-web-browser google-chrome.desktop |
| 99 | 117 |
| 100 | 118 Set the default mailto URL scheme handler to be |
| 119 evolution.desktop |
| 120 xdg-settings set default-url-scheme-handler evolution.desktop |
| 101 _MANUALPAGE | 121 _MANUALPAGE |
| 102 } | 122 } |
| 103 | 123 |
| 104 usage() | 124 usage() |
| 105 { | 125 { |
| 106 cat << _USAGE | 126 cat << _USAGE |
| 107 xdg-settings - get various settings from the desktop environment | 127 xdg-settings - get various settings from the desktop |
| 128 environment |
| 108 | 129 |
| 109 Synopsis | 130 Synopsis |
| 110 | 131 |
| 111 xdg-settings { get | check | set } {property} [value] | 132 xdg-settings { get | check | set } {property} [subproperty] |
| 133 [value] |
| 112 | 134 |
| 113 xdg-settings { --help | --list | --manual | --version } | 135 xdg-settings { --help | --list | --manual | --version } |
| 114 | 136 |
| 115 _USAGE | 137 _USAGE |
| 116 } | 138 } |
| 117 | 139 |
| 118 #@xdg-utils-common@ | 140 #@xdg-utils-common@ |
| 119 | 141 |
| 120 #---------------------------------------------------------------------------- | 142 #---------------------------------------------------------------------------- |
| 121 # Common utility functions included in all XDG wrapper scripts | 143 # Common utility functions included in all XDG wrapper scripts |
| 122 #---------------------------------------------------------------------------- | 144 #---------------------------------------------------------------------------- |
| 123 | 145 |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/applications" | 554 mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/applications" |
| 533 xdg-mime default "$1" "$MIME" || return | 555 xdg-mime default "$1" "$MIME" || return |
| 534 if [ x"`get_browser_mime`" != x"$1" ]; then | 556 if [ x"`get_browser_mime`" != x"$1" ]; then |
| 535 # Put back the original value | 557 # Put back the original value |
| 536 xdg-mime default "$orig" "$MIME" | 558 xdg-mime default "$orig" "$MIME" |
| 537 exit_failure_operation_failed | 559 exit_failure_operation_failed |
| 538 fi | 560 fi |
| 539 } | 561 } |
| 540 | 562 |
| 541 # }}} MIME utilities | 563 # }}} MIME utilities |
| 564 # {{{ KDE utilities |
| 565 |
| 566 # Reads the KDE configuration setting, compensating for a bug in some versions o
f kreadconfig. |
| 567 read_kde_config() |
| 568 { |
| 569 configfile="$1" |
| 570 configsection="$2" |
| 571 configkey="$3" |
| 572 browser="`kreadconfig --file $configfile --group $configsection --key $confi
gkey`" |
| 573 if [ x"$browser" != x ]; then |
| 574 echo "$browser" |
| 575 else |
| 576 # kreadconfig in KDE 4 may not notice Key[$*]=... localized settings, so |
| 577 # check by hand if it didn't find anything (oddly kwriteconfig works |
| 578 # fine though). |
| 579 kdeglobals_dir=`kde${KDE_SESSION_VERSION}-config --path config | cut -d
':' -f 1` |
| 580 kdeglobals="$kdeglobals_dir/$configfile" |
| 581 [ ! -f "$kdeglobals" ] && return |
| 582 # This will only take the first value if there is more than one. |
| 583 grep "^$configkey"'\[$[^]=]*\]=' "$kdeglobals" | head -n 1 | cut -d= -f
2- |
| 584 fi |
| 585 } |
| 586 |
| 587 # }}} KDE utilities |
| 542 # {{{ KDE | 588 # {{{ KDE |
| 543 | 589 |
| 544 # Resolves the KDE browser setting to a binary: if prefixed with !, simply remov
es it; | 590 # Resolves the KDE browser setting to a binary: if prefixed with !, simply remov
es it; |
| 545 # otherwise, uses desktop_file_to_binary to get the binary out of the desktop fi
le. | 591 # otherwise, uses desktop_file_to_binary to get the binary out of the desktop fi
le. |
| 546 resolve_kde_browser() | 592 resolve_kde_browser() |
| 547 { | 593 { |
| 548 [ -z "$browser" ] && return | 594 [ -z "$browser" ] && return |
| 549 case "$browser" in | 595 case "$browser" in |
| 550 !*) | 596 !*) |
| 551 echo "${browser#!}" | 597 echo "${browser#!}" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 565 !*) | 611 !*) |
| 566 desktop="`binary_to_desktop_file "${browser#!}"`" | 612 desktop="`binary_to_desktop_file "${browser#!}"`" |
| 567 basename "$desktop" | 613 basename "$desktop" |
| 568 ;; | 614 ;; |
| 569 *) | 615 *) |
| 570 echo "$browser" | 616 echo "$browser" |
| 571 ;; | 617 ;; |
| 572 esac | 618 esac |
| 573 } | 619 } |
| 574 | 620 |
| 575 # Reads the KDE browser setting, compensating for a bug in some versions of krea
dconfig. | |
| 576 read_kde_browser() | 621 read_kde_browser() |
| 577 { | 622 { |
| 578 browser="`kreadconfig --file kdeglobals --group General --key BrowserApplica
tion`" | 623 read_kde_config kdeglobals General BrowserApplication |
| 579 if [ x"$browser" != x ]; then | |
| 580 echo "$browser" | |
| 581 else | |
| 582 # kreadconfig in KDE 4 may not notice Key[$*]=... localized settings, so | |
| 583 # check by hand if it didn't find anything (oddly kwriteconfig works | |
| 584 # fine though). | |
| 585 kdeglobals_dir=`kde${KDE_SESSION_VERSION}-config --path config | cut -d
':' -f 1` | |
| 586 kdeglobals="$kdeglobals_dir/kdeglobals" | |
| 587 [ ! -f "$kdeglobals" ] && return | |
| 588 # This will only take the first value if there is more than one. | |
| 589 grep '^BrowserApplication\[$[^]=]*\]=' "$kdeglobals" | head -n 1 | cut -
d= -f 2- | |
| 590 fi | |
| 591 } | 624 } |
| 592 | 625 |
| 593 get_browser_kde() | 626 get_browser_kde() |
| 594 { | 627 { |
| 595 browser="`read_kde_browser`" | 628 browser="`read_kde_browser`" |
| 596 if [ x"$browser" = x ]; then | 629 if [ x"$browser" = x ]; then |
| 597 # No explicit default browser; KDE will use the MIME type text/html. | 630 # No explicit default browser; KDE will use the MIME type text/html. |
| 598 get_browser_mime | 631 get_browser_mime |
| 599 else | 632 else |
| 600 resolve_kde_browser_desktop | 633 resolve_kde_browser_desktop |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 mv "$temp" "$helpers_rc" | 869 mv "$temp" "$helpers_rc" |
| 837 else | 870 else |
| 838 rm -f "$temp" | 871 rm -f "$temp" |
| 839 return 1 | 872 return 1 |
| 840 fi | 873 fi |
| 841 } | 874 } |
| 842 | 875 |
| 843 # }}} xfce | 876 # }}} xfce |
| 844 # }}} default browser | 877 # }}} default browser |
| 845 | 878 |
| 879 # {{{ default url scheme handler |
| 880 |
| 881 exit_unimplemented_default_handler() |
| 882 { |
| 883 exit_failure_operation_impossible "default-url-scheme-handler not implemente
d for $DE" |
| 884 } |
| 885 |
| 886 # {{{ KDE |
| 887 |
| 888 # Recent versions of KDE support default scheme handler applications using the m
ime type |
| 889 # of x-scheme-handler/scheme. Older versions will not support this but do have s
upport |
| 890 # for setting a default mail handler. There is also a system in KDE where .proto
col files |
| 891 # can be used, however this is not supported by this script. |
| 892 # When reading a scheme handler we will use the default mail handler for the mai
lto scheme, |
| 893 # otherwise we will use the mime type x-scheme-handler/scheme. |
| 894 |
| 895 get_url_scheme_handler_kde() |
| 896 { |
| 897 if [ "$1" = "mailto" ]; then |
| 898 handler="`read_kde_config emaildefaults PROFILE_Default EmailClient | fi
rst_word`" |
| 899 echo "handler is $handler" |
| 900 if [ x"$handler" != x ]; then |
| 901 binary_to_desktop_file "$handler" |
| 902 else |
| 903 get_browser_mime "x-scheme-handler/$1" |
| 904 fi |
| 905 else |
| 906 get_browser_mime "x-scheme-handler/$1" |
| 907 fi |
| 908 } |
| 909 |
| 910 check_url_scheme_handler_kde() |
| 911 { |
| 912 check="`desktop_file_to_binary "$2"`" |
| 913 if [ -z "$check" ]; then |
| 914 echo no |
| 915 exit_success |
| 916 fi |
| 917 if [ x"$1" = "mailto" ]; then |
| 918 binary="`read_kde_config emaildefaults PROFILE_Default EmailClient`" |
| 919 if [ x"$binary" != x"$check" ]; then |
| 920 echo no |
| 921 exit_success |
| 922 fi |
| 923 fi |
| 924 handler="`get_browser_mime x-scheme-handler/$1`" |
| 925 binary="`desktop_file_to_binary "$handler"`" |
| 926 if [ x"$binary" != x"$check" ]; then |
| 927 echo no |
| 928 exit_success |
| 929 fi |
| 930 echo yes |
| 931 exit_success |
| 932 } |
| 933 |
| 934 set_url_scheme_handler_kde() |
| 935 { |
| 936 set_browser_mime "$2" "x-scheme-handler/$1" || return |
| 937 if [ "$1" = "mailto" ]; then |
| 938 binary="`desktop_file_to_binary "$2"`" |
| 939 kwriteconfig --file emaildefaults --group PROFILE_Default --key EmailCli
ent "$binary" |
| 940 fi |
| 941 } |
| 942 |
| 943 # }}} KDE |
| 944 # {{{ GNOME |
| 945 |
| 946 get_url_scheme_handler_gnome() |
| 947 { |
| 948 binary="`gconftool-2 --get /desktop/gnome/url-handlers/$1/command | first_wo
rd`" |
| 949 if [ x"$binary" != x"" ]; then |
| 950 # gconftool gives the binary (maybe with %s etc. afterward), |
| 951 # but we want the desktop file name, not the binary. So, we |
| 952 # have to find the desktop file to which it corresponds. |
| 953 desktop="`binary_to_desktop_file "$binary"`" |
| 954 basename "$desktop" |
| 955 fi |
| 956 } |
| 957 |
| 958 check_url_scheme_handler_gnome() |
| 959 { |
| 960 check="`desktop_file_to_binary "$2"`" |
| 961 if [ -z "$check" ]; then |
| 962 echo no |
| 963 exit_success |
| 964 fi |
| 965 binary="`gconftool-2 --get /desktop/gnome/url-handlers/$1/command | first_wo
rd`" |
| 966 if [ x"$binary" != x"$check" ]; then |
| 967 echo no |
| 968 exit_success |
| 969 fi |
| 970 echo yes |
| 971 exit_success |
| 972 } |
| 973 |
| 974 set_url_scheme_handler_gnome() |
| 975 { |
| 976 binary="`desktop_file_to_binary "$2"`" |
| 977 [ "$binary" ] || exit_failure_file_missing |
| 978 |
| 979 gconftool-2 --type string --set /desktop/gnome/url-handlers/$1/command "$bin
ary %s" |
| 980 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$1/needs_terminal
false |
| 981 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$1/enabled true |
| 982 } |
| 983 |
| 984 # }}} GNOME |
| 985 # {{{ GNOME 3.x |
| 986 |
| 987 get_url_scheme_handler_gnome3() |
| 988 { |
| 989 get_browser_mime "x-scheme-handler/$1" |
| 990 } |
| 991 |
| 992 check_url_scheme_handler_gnome3() |
| 993 { |
| 994 desktop="$2" |
| 995 check="`desktop_file_to_binary "$2"`" |
| 996 if [ -z "$check" ]; then |
| 997 echo no |
| 998 exit_success |
| 999 fi |
| 1000 browser="`get_browser_mime "x-scheme-handler/$1"`" |
| 1001 if [ x"$browser" != x"$desktop" ]; then |
| 1002 echo no |
| 1003 exit_success |
| 1004 fi |
| 1005 echo yes |
| 1006 exit_success |
| 1007 } |
| 1008 |
| 1009 set_url_scheme_handler_gnome3() |
| 1010 { |
| 1011 binary="`desktop_file_to_binary "$2"`" |
| 1012 [ "$binary" ] || exit_failure_file_missing |
| 1013 set_browser_mime "$2" || return |
| 1014 |
| 1015 # Set the default browser. |
| 1016 set_browser_mime "$2" "x-scheme-handler/$1" || return |
| 1017 } |
| 1018 |
| 1019 # }}} GNOME 3.x |
| 1020 # {{{ xfce |
| 1021 |
| 1022 get_url_scheme_handler_xfce() |
| 1023 { |
| 1024 exit_unimplemented_default_handler "$1" |
| 1025 } |
| 1026 |
| 1027 check_url_scheme_handler_xfce() |
| 1028 { |
| 1029 exit_unimplemented_default_handler "$1" |
| 1030 } |
| 1031 |
| 1032 set_url_scheme_handler_xfce() |
| 1033 { |
| 1034 exit_unimplemented_default_handler "$1" |
| 1035 } |
| 1036 |
| 1037 # }}} xfce |
| 1038 # }}} default protocol handler |
| 1039 |
| 846 dispatch_specific() | 1040 dispatch_specific() |
| 847 { | 1041 { |
| 848 # The PROP comments in this function are used to generate the output of | 1042 # The PROP comments in this function are used to generate the output of |
| 849 # the --list option. The formatting is important. Make sure to line up the | 1043 # the --list option. The formatting is important. Make sure to line up the |
| 850 # property descriptions with spaces so that it will look nice. | 1044 # property descriptions with spaces so that it will look nice. |
| 851 if [ x"$op" = x"get" ]; then | 1045 if [ x"$op" = x"get" ]; then |
| 852 case "$parm" in | 1046 case "$parm" in |
| 853 default-web-browser) # PROP: Default web browser | 1047 default-web-browser) # PROP: Default web browser |
| 854 get_browser_$DE | 1048 get_browser_$DE |
| 855 ;; | 1049 ;; |
| 856 | 1050 |
| 1051 default-url-scheme-handler) # PROP: Default handler for url scheme |
| 1052 get_url_scheme_handler_$DE "$1" |
| 1053 ;; |
| 1054 |
| 857 *) | 1055 *) |
| 858 exit_failure_syntax | 1056 exit_failure_syntax |
| 859 ;; | 1057 ;; |
| 860 esac | 1058 esac |
| 861 elif [ x"$op" = x"check" ]; then | 1059 elif [ x"$op" = x"check" ]; then |
| 862 case "$parm" in | 1060 case "$parm" in |
| 863 default-web-browser) | 1061 default-web-browser) |
| 864 check_desktop_filename "$1" | 1062 check_desktop_filename "$1" |
| 865 check_browser_$DE "$1" | 1063 check_browser_$DE "$1" |
| 866 ;; | 1064 ;; |
| 867 | 1065 |
| 1066 default-*-handler) |
| 1067 check_desktop_filename "$2" |
| 1068 check_url_scheme_handler_$DE "$1" "$2" |
| 1069 ;; |
| 1070 |
| 868 *) | 1071 *) |
| 869 exit_failure_syntax | 1072 exit_failure_syntax |
| 870 ;; | 1073 ;; |
| 871 esac | 1074 esac |
| 872 else # set | 1075 else # set |
| 873 [ $# -eq 1 ] || exit_failure_syntax "unexpected/missing argument" | |
| 874 case "$parm" in | 1076 case "$parm" in |
| 875 default-web-browser) | 1077 default-web-browser) |
| 1078 [ $# -eq 1 ] || exit_failure_syntax "unexpected/missing argument" |
| 876 check_desktop_filename "$1" | 1079 check_desktop_filename "$1" |
| 877 set_browser_$DE "$1" | 1080 set_browser_$DE "$1" |
| 878 ;; | 1081 ;; |
| 879 | 1082 |
| 1083 default-*-handler) |
| 1084 [ $# -eq 2 ] || exit_failure_syntax "unexpected/missing argument" |
| 1085 check_desktop_filename "$2" |
| 1086 set_url_scheme_handler_$DE "$1" "$2" |
| 1087 ;; |
| 1088 |
| 880 *) | 1089 *) |
| 881 exit_failure_syntax | 1090 exit_failure_syntax |
| 882 ;; | 1091 ;; |
| 883 esac | 1092 esac |
| 884 fi | 1093 fi |
| 885 | 1094 |
| 886 if [ $? -eq 0 ]; then | 1095 if [ $? -eq 0 ]; then |
| 887 exit_success | 1096 exit_success |
| 888 else | 1097 else |
| 889 exit_failure_operation_failed | 1098 exit_failure_operation_failed |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 ;; | 1165 ;; |
| 957 | 1166 |
| 958 generic) | 1167 generic) |
| 959 dispatch_generic "$@" | 1168 dispatch_generic "$@" |
| 960 ;; | 1169 ;; |
| 961 | 1170 |
| 962 *) | 1171 *) |
| 963 exit_failure_operation_impossible "unknown desktop environment" | 1172 exit_failure_operation_impossible "unknown desktop environment" |
| 964 ;; | 1173 ;; |
| 965 esac | 1174 esac |
| OLD | NEW |