-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxwinid
More file actions
executable file
·46 lines (42 loc) · 1.19 KB
/
xwinid
File metadata and controls
executable file
·46 lines (42 loc) · 1.19 KB
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
#!/bin/sh
# (c) Copyright 2017 Jonathan Simmonds
# Tiny wrapper on top of xwininfo to grab just the Window ID in decimal.
# This is only really useful if you are scripting a windowing utility as
# xwininfo does not offer a machine readable output form.
set -e
usage()
{
echo "usage: xwinid [window-name]"
echo ""
echo "Tiny wrapper on top of xwininfo to grab just the Window ID in decimal."
echo ""
echo "positional arguments:"
echo " window-name Optional name of the window to query. If ommitted the"
echo " cursor will be used to select the window to query."
echo ""
echo "optional arguments:"
echo " -h, --help Print this message and exit."
exit 1
}
# Script variables
XWINARGS=""
SCRIPT_DIR=$(readlink -f "$0" | xargs dirname)
# Handle command line
while [ $# -gt 0 ]; do
command_line_arg="$1"
shift
case "$command_line_arg" in
-h)
usage
;;
--help)
usage
;;
*)
XWINARGS="-name $command_line_arg"
;;
esac
done
# Actual implementation
XID=$(xwininfo -int ${XWINARGS} | grep -Po "Window id: [0-9]+" | grep -Po "[0-9]+$")
echo $XID