Hello after a long period of silence.
I've been entertaining the idea of creating a new personal website for a technical blog. This was sparked by applying for new jobs recently, and needing to update my resume and git repositories. I found I didn't really have much to show in the public space aside from the web control script, which hasn't been working on in a while. Zackman and I have agree'd we could rewrite the whole program in a much better way if we were to do it again. Whether that will happen or not is still an ongoing discussion, and a matter of time :) But since I was only thinking about a new blog, I haven't yet created one. For now, this is not a bad place to keep some fun tech stuff going!
I have only recently discovered Apple Scripts as a method of automating tasks on a Mac. I don't yet know the scope of what it allows, but it does seem more things can be customized than I originally thought.
In this random new post out of nowhere, I'm basically copying what's been shown in howchoo's blog post for creating a keyboard shortcut to connect to airpods. At my new job (my resume updated paid off) I've been utilizing my Airpod's a lot more. It's been a minor annoyance that sometimes they don't always auto-connect to my Macbook. They seem to struggle to recognize when they should be connected to my phone, ipad, or my laptop. Having a keyboard shortcut to force a connection would save a lot of time, and more importantly, keep me from diverting my focus. Between howchoo's post, a reddit post, and apple's documentation, I've found a solution customized to me that I like. For prosperity and the chance I'll have to go through all of this again, here's a record of my own spin on things.
use framework "IOBluetooth" use scripting additions set AirPodsName to "Stud’s AirPods Pro" on getFirstMatchingDevice(deviceName) repeat with device in (current application's IOBluetoothDevice's pairedDevices() as list) if (device's nameOrAddress as string) contains deviceName then return device end repeat end getFirstMatchingDevice on toggleDevice(device) if not (device's isConnected as boolean) then device's openConnection() display notification "" with title "AirPods connecting..." sound name "Frog" return "Connecting " & (device's nameOrAddress as string) else -- device's closeConnection() -- return "Disconnecting " & (device's nameOrAddress as string) display notification "" with title "AirPods already connected" sound name "Frog" return (device's nameOrAddress as string) & " Already connected" end if end toggleDevice return toggleDevice(getFirstMatchingDevice(AirPodsName))
This is an improvement on howchoo's code, and with the supposed addition of display notifications. I say supposed, because when this should give me a simple pop-up, but when I run it from my keyboard shortcut, this doesn't happen. It works from the Script Editor though. So it's close.
If I figure out this piece to complete this, I'll update this blog. If you have any idea's check out my gitlab snippet to comment.
On a random finishing note, I see that the blog formatting is cutting off some text.
I'll have to look into this as well. I apologize for the malformation...