-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckDeviceStatus.sh
More file actions
46 lines (41 loc) · 915 Bytes
/
CheckDeviceStatus.sh
File metadata and controls
46 lines (41 loc) · 915 Bytes
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
#!/usr/bin/env bash
set -e
if [[ ! "${@}" ]];
then
if [[ -z "${DEVICE_TO_CHECK}" ]];
then
echo "ERROR: No device was given."
exit -1
else
DEVICE_TO_CHECK="${DEVICE_TO_CHECK}"
fi
else
DEVICE_TO_CHECK="${1}"
fi
get_device_status() {
if [[ "$(ioreg -p IOUSB | grep -i "${DEVICE_TO_CHECK}")" ]]
then
echo "plugged"
fi
}
change_settings() {
if [[ "$(get_device_status)" == "plugged" ]]
then
/usr/local/bin/SwitchKeyboard "British-PC"
/usr/local/bin/SwitchScrollDirection "Standard"
else
/usr/local/bin/SwitchKeyboard "British"
/usr/local/bin/SwitchScrollDirection "Natural"
fi
}
_prev_status="$(get_device_status)"
change_settings
while true
do
if [[ "$(get_device_status)" != "${_prev_status}" ]]
then
_prev_status="$(get_device_status)"
change_settings
fi
sleep 3
done