Hammerspoon – Automating Brave Browser and Airpods

Hammerspoon was a great tool to help me improve my OSX interaction layer and to keep focus.

As I continue my documentation of Hammerspoon, I’m going expand on and dive in to a few modules I access with hyper: brave.lua or airpods.lua.

Brave.lua: automating my browser

While I use the Brave Browser for quite a while, I didn’t want Google giving me any additional information. Firefox has no automation hooks so I decided to switch to Firefox.

The brave.lua module contains two parts. There are two parts to the configuration table. I’ve provided some assistance methods in init.lua.

For brave.lua setup, you will require this and must pass any configurations you’ve created.

Configuration

=

Configure

Domains

=

{

"

www.twitter.com

[

=

{

Click here

=

www.twitter.com

Tags

=

{

#distraction>

'#socialmedia'

|•||}

,|The following is a list of.|•|You can find it at.}

|•||}

Local

Be brave

=

You must

(

The 'brave'

(

Be brave

Start

(

Configuration

(

While not required, it makes certain functions simpler by configuring the domains.

You have now access to the brave functions. Because I frequently use Google Meet, the reason it was written is simple. Meet, unlike Zoom runs in a web browser tab. It was something I had come to rely on to bring up Zoom, to make it unmuted when I was mentioned.

hyper

These are the words:

Bind

(,

Use the 'z’ option to get started.

Null

Funktion

()

Be brave

jump

(

"meet.google.com|hangouts.google.com.call"

(

End

(

This is my “jumpto video button”, in action. the hotkey triggers my Hypermodal. No matter what tab you choose, the Hyper modal always focuses on the appropriate tab. It doesn’t matter what tab or window it opens, it will always focus the appropriate window and tab.

This is a very useful UX trick. I used my muscle memory to push the button to “jump into video chat.” Now it works regardless of what app or program I’m in.

In actuality, I have the same key in my current version for zoom, meet or hangouts…

Jump to Zoom and Google Hangout

hyper

These are the words:

Bind

(,

Use the 'z’ option to get started.

Null

Function

()

If

hs

Application

Learn more

(

us.zoom.xos>

(

then

hs

Application

launchOrFocusByBundleID

(

us.zoom.xos>

(

Another

Be brave

jump

(

"meet.google.com|hangouts.google.com.call"

(

End

End

(

(From init.lua).

A key point is to always keep the camera focused on my question. One key, and that is to always keep the camera focused when I am asked a question.

brave.jump() uses a JXA, which I believe was adapted from an AppleScript I found. I then rewrote it. is the complete. This highlights Hammerspoon’s capability to run random scripts, based on the inputs and environments you provide.

It’s the same thing I use for a couple of other things. A key that focuses Figma.app on the Figma.com website or Lucidchart. This is basically a button that says “show me how my visual design”. It’s amazing.

You will find additional features within brave.lua in the future posts.

airpods.lua

While it’s not an important trick, this is one I use every day. There wasn’t a way to connect AirPods and computers with just one keypress. At least 3 menubar programs are available now in the App Market, but Mine is free.

I downloaded some AppleScript from @daGrevis to connect AirPods. The lua module required and specified the AirPods names and then it was connected to my Hyper modal layer. The rest is easy.

local

Airpods

=

You must

(

"Airpods".

(

hyper

These are the words:

Bind

(,

It is a hyphen

Null

Function

()

local

All rights reserved

Product

=

airpods

Switch

(

'Evan's AirPods’

(

If

All rights reserved

then

hs

Alert

Show

(

Product

(

Another

hs

Alert

Show

(

AirPods cannot be connected

(

End

End

(

Additional Bonus: Snip browser to drafts as a SimpleMarkdown Zettelkasten

My simple Markdown Zettelkasten often starts in my browser. Drafts.app is compatible with Safari. Brave has an integrated share option. It is necessary to create something new.

Drafts.app offered a very simple AppleScript-api. I finally was able do it. It is necessary to make Brave enable this option: View-> Developer-> Allow Javascript From Apple Events.

Brave Highlights: Snip

Hyper

These are the words:

Bind

(,

You can find it at s>

Null

function

()

hs

osascript

applescript

(

[[ -- stolen from: https://gist.github.com/gabeanzelini/1931128eb233b0da8f51a8d165b418fa if (count of theSelectionFromBrave()) is greater than 0 then set str to "tags: #link\n\n" & theTitleFromBrave() & "\n\n> " & theSelectionFromBrave() & "\n\n[" & theTitleFromBrave() & "](" & theCurrentUrlInBrave() & ")" tell application "Drafts" make new draft with properties content:str, tags: "link" end tell end if on theCurrentUrlInBrave() tell application "Brave Browser" to get the URL of the active tab in the first window end theCurrentUrlInBrave on theSelectionFromBrave() tell application "Brave Browser" to execute front window's active tab javascript "getSelection().toString();" end theSelectionFromBrave on theTitleFromBrave() tell application "Brave Browser" to get the title of the active tab in the first window end theTitleFromBrave ]]

(

hs

Notify

Show

(

"Snipped!"

Drafts have received "The snippet"

"

(

End

(

(From imit.lua

Let me highlight the paragraphs in your article and you will see what it does.

Tags: #link Hammerspoon Automation of Brave Browser and Airpods 

Drafts.app offered a very simple AppleScript-api. This was the moment I realized that this could be done. It is necessary to make Brave allow Javascript from Apple Events.

"

Hammerspoon - Automating Brave Browser and Airpods

[(

http://evantravers.com/articles/2020/06/11/hammerspoon-automating-airpods-and-brave-browser/

(

They are kept in a Workspace called Drafts, which I use to save to disk later or to send to friends.