-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwt-ask
executable file
·100 lines (87 loc) · 2.28 KB
/
wt-ask
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh
# Copyright (C) 2014 Francois Gouget
#
# Asks a simple Yes/No question.
#
# 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; either version 2 of the License, or
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.
name0=`basename "$0"`
error()
{
echo "$name0:error:" "$@" >&2
}
#
# Command line processing
#
opt_msg=""
usage=""
while [ $# -gt 0 ]
do
arg="$1"
shift
if [ "$arg" = "--help" -o "$arg" = "-h" -o "$arg" = "-?" ]
then
usage=0
break
elif [ -z "$opt_msg" ]
then
opt_msg="$arg"
else
error "unknown option '$arg'"
usage=2
break
fi
done
if [ -z "$usage" ]
then
if [ -z "$opt_msg" ]
then
error "you must provide the text of the question"
usage=2
fi
fi
if [ "$usage" = "0" ]
then
echo "Usage: $name0 [--help] QUESTION"
echo
echo "Asks a simple Yes/No question to the user."
echo
echo "Where:"
echo " QUESTION This is the text of the question. The answer will be Yes or No."
echo " --help, -h Shows this help message."
exit 0
elif [ -n "$usage" ]
then
error "try '$name0 --help' for more information"
exit $usage
fi
#
# Ask the question
#
if type osascript >/dev/null 2>&1
then
# This is Mac OS X but osascript provides no usable way of asking such a
# question ('display dialog' is too buggy).
exec python -c "from AppKit import NSAlert, NSApplication
NSApplication.sharedApplication().activateIgnoringOtherApps_(True)
res = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_('$opt_msg', 'No', 'Yes', None, '').runModal()
import sys
sys.exit(res)"
else
if [ -z "$DISPLAY" ]
then
DISPLAY=":0.0"
export DISPLAY
fi
exec zenity --question --text "$opt_msg" 2>/dev/null
fi