mirror of
https://github.com/d0zingcat/dotfiles.git
synced 2026-05-22 07:26:54 +00:00
42 lines
1017 B
Swift
Executable File
42 lines
1017 B
Swift
Executable File
#!/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()
|