Skip to content

Instantly share code, notes, and snippets.

@wilmoore
Last active October 26, 2024 02:33
Show Gist options
  • Select an option

  • Save wilmoore/423a48429bae2abfc441d2f7beea3144 to your computer and use it in GitHub Desktop.

Select an option

Save wilmoore/423a48429bae2abfc441d2f7beea3144 to your computer and use it in GitHub Desktop.
Personal Brand :: Social Media :: LinkedIn :: Post :: Pong...Your bluetooth device is now connected!

Personal Brand :: Social Media :: LinkedIn :: Post :: Pong...Your bluetooth device is now connected!

⪼ Made with 💜 by Polyglot.

research
» Pong… Your Bluetooth device is now connected «

Bluetooth — it’s a little quirky, sure, but ultimately, pretty darn impressive.

Think about it...

↳ Connect your phone to your car
↳ Pair your headphones with your phone
↳ Sync your headphones with your laptop
↳ Stream from your laptop to your speakers

But here’s the rub: once two devices are paired, switching to another one can feel like a wrestling match. If you’ve put away one of the devices, you have to track it down, power it on, and unpair it just to reconnect somewhere else. Smooth, right?

This cycle gets me every time with the holy trinity of my laptop, headphones, and iPhone.

Imagine this: I’m deep in work, headphones on, totally in the zone. But then, I decide to step out for a walk.

↳ I grab my phone
↳ Slip on my shoes
↳ Throw on my backpack

…and I’m out the door.

I open up SoundCloud, hit play on my favorite playlist, and then I hear:

“Pong… Power Off!”

Ugh. I forgot to unpair my headphones from my laptop. Back inside I go, log back into my laptop, and fire up Raycast.

One quick “f” command, and Raycast autocompletes to the exact script I need.

That “Bluetooth Forget” script I wrote? It’s a lifesaver. A simple bash command that instantly unpairs my Bluetooth device from my laptop.

With my shortcut key and a couple of taps — no mouse, no touchpad — the device is unpaired, and I’m good to go. Now I can hit the trail without interruption, and let my thoughts marinate without losing a single detail.

“Bluetooth Forget” just... works.

Țechśavvy CEO

P.S. don't forget to `brew install blueutil` or the script won't work.

image

💭 Curious about making your own script commands to streamline workflows? Check out Raycast’s Script Commands on GitHub to get started! Or if you’ve already tried it, share your favorite commands with me below 👇🏾

https://github.com/raycast/script-commands
source
#!/usr/bin/env bash

# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Bluetooth Forget
# @raycast.mode silent

# Optional parameters:
# @raycast.icon 🎧
# @raycast.packageName m3

# Documentation:
# @raycast.author wilmoore
# @raycast.authorURL https://linkedin.com/in/wilmoore

# Device MAC Address
MAC_ADDRESS="61-0c-0d-0b-7c-4b"

# Check if the device is paired
PAIRED_DEVICES=$(blueutil --paired)

if echo "$PAIRED_DEVICES" | grep -q "$MAC_ADDRESS"; then
  # Attempt to forget the device
  blueutil --unpair "$MAC_ADDRESS"

  # Retry checking if the device has been unpaired
  MAX_RETRIES=5
  RETRY_DELAY=4
  RETRIES=0
  SUCCESS=false

  while [ $RETRIES -lt $MAX_RETRIES ]; do
    sleep $RETRY_DELAY

    PAIRED_DEVICES=$(blueutil --paired)
    if ! echo "$PAIRED_DEVICES" | grep -q "$MAC_ADDRESS"; then
      SUCCESS=true
      break
    fi

    ((RETRIES++))
  done

  if [ "$SUCCESS" = true ]; then
    echo "Device $MAC_ADDRESS has been successfully unpaired."
  else
    echo "Failed to unpair device $MAC_ADDRESS after $MAX_RETRIES attempts. Please try again."
  fi
else
  # Provide feedback if the device isn't paired
  echo "Device $MAC_ADDRESS is not currently paired or is powered off."
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment