-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqdbus-call-service-method
executable file
·50 lines (42 loc) · 1.12 KB
/
qdbus-call-service-method
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
#!/usr/bin/env sh
# vim: ft=sh ts=4 sw=4 sts=4 et :
# Check if a command exists
has() {
command -v "$1" >/dev/null 2>&1
}
# Print usage message
usage() {
printf "Usage: %s <service name> <method name> [method arguments]\n" \
"$(basename "$0")" >&2
}
main() {
if has qdbus; then
qdbus_cmd="qdbus"
elif has qdbus6; then
qdbus_cmd="qdbus6"
else
echo "Error: neither qdbus nor qdbus6 found" >&2
exit 1
fi
if [ -z "$1" ] || [ -z "$2" ]; then
usage
exit 1
fi
service_pattern="$1"
method_name="$2"
shift 2
# List all matching services
services=$("$qdbus_cmd" | grep -i "$service_pattern") || {
exit 1
}
printf '%s\n' "$services" | while read -r service; do
objects=$("$qdbus_cmd" "$service") || continue
printf '%s\n' "$objects" | while read -r obj; do
methods=$("$qdbus_cmd" "$service" "$obj") || continue
if printf '%s\n' "$methods" | grep -q "$method_name"; then
"$qdbus_cmd" "$service" "$obj" "$method_name" "$@"
fi
done
done
}
main "$@"