-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoggle-airpods.swift
executable file
·42 lines (35 loc) · 1018 Bytes
/
toggle-airpods.swift
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
#!/usr/bin/swift
// Required parameters:
// @raycast.schemaVersion 1
// @raycast.title Toggle AirPods
// @raycast.mode silent
// @raycast.packageName Audio
//
// Optional parameters:
// @raycast.icon images/airpod.png
//
// Documentation:
// @raycast.description Toggle AirPods bluetooth device
// @raycast.author Nichlas W. Andersen
// @raycast.authorURL https://github.com/itsnwa
import IOBluetooth
// Get your device's MAC address by option (⌥) + clicking the bluetooth icon in the menu bar
let deviceAddress = ""
func toggleAirPods() {
guard let bluetoothDevice = IOBluetoothDevice(addressString: deviceAddress) else {
print("Device not found")
exit(1)
}
if !bluetoothDevice.isPaired() {
print("Device not paired")
exit(1)
}
if bluetoothDevice.isConnected() {
print("AirPods Disconnected")
bluetoothDevice.closeConnection()
} else {
print("AirPods Connected")
bluetoothDevice.openConnection()
}
}
toggleAirPods()