Hammerspoon was a great tool to help me improve my OSX interaction layer and to keep focus.
As I document Hammerspoon, I plan to continue on hyper.lua. I also dive into modules with basic functionality that I can access using 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
=
Configuration
Domains
=
{
"
www.twitter.com
[
=
{
URL
=
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
(
Configure
(
While not required, it makes certain functions simpler by configuring the domains.
Now you are able to access all of brave’s 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 was used to doing when I heard someone say it, so I wanted to be able to use the same function in Google Meet.
Hyper
These are the words:
Bind
(,
Use the 'z’ option to get started.
Null
function
()
Be brave
jump
(
"meet.google.com|hangouts.google.com.call"
(
End
(
This is my “jumpto video button”, in action. the hotkey triggers my Hypermodal. It doesn’t matter what window it opens, or which tab is open, the Hyper modal always focuses on the appropriate window and tab. No matter what tab or window it opens, the focus is always on the appropriate tab and window.
This is a very useful UX trick. I used my muscle memory to push the button to “jump into video chat,” so now it works regardless of what app or program I’m in.
My current implementation supports the same key, zoom, meet or hangouts.
Jump to zoom or 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. It 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 keystroke. At least 3 menubar programs are available on the App Market, though mine can be downloaded for free.
I downloaded some AppleScript by @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
None
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. there is a better way.
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 init.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.