-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhs
executable file
·66 lines (60 loc) · 1.56 KB
/
hs
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
#!/bin/bash
# Device IDs
DEVICE_SONY="94-db-56-6e-d9-34"
DEVICE_NOTHING="2c-be-eb-0b-1c-ee"
BLUEUTIL_CMD="blueutil"
# Check if blueutil is installed
if ! command -v $BLUEUTIL_CMD &> /dev/null; then
echo "$BLUEUTIL_CMD could not be found."
read -p "Do you want to install blueutil? (y/n) " answer
case ${answer:0:1} in
y|Y )
echo "Installing blueutil..."
brew install blueutil
if [ $? -ne 0 ]; then
echo "Installation failed. Please install blueutil manually."
exit 1
fi
;;
* )
echo "blueutil is required to run this script."
exit 1
;;
esac
fi
# Function to connect to a device
connect_device() {
if [ `$BLUEUTIL_CMD --is-connected $2` -eq 0 ]; then
echo "Connecting to $1..."
$BLUEUTIL_CMD --connect $2
else
echo "$1 is already connected."
fi
}
# Function to disconnect a device
disconnect_device() {
if [ `$BLUEUTIL_CMD --is-connected $2` -eq 1 ]; then
echo "Disconnecting $1..."
$BLUEUTIL_CMD --disconnect $2
else
echo "$1 is already disconnected."
fi
}
# Main logic using case statement
case $1 in
"-cs")
connect_device "Sony" $DEVICE_SONY
;;
"-cn")
connect_device "Nothing" $DEVICE_NOTHING
;;
"-ds")
disconnect_device "Sony" $DEVICE_SONY
;;
"-dn")
disconnect_device "Nothing" $DEVICE_NOTHING
;;
*)
echo "Invalid option. Use -cs, -cn, -ds, or -dn."
;;
esac