As a result, it's possible that something broke which we didn't find in our internal testing. Please file GitHub issues :)
Happy Christmas y'all!
Speaking of old and terrible... Are you planning to keep the project in Objective-C long term? Any chance of migrating to Swift?
Merry Christmas and thanks for a great project.
One side I've noticed Hammesrpoon is a bit difficult to work with is debugging it can be done with logging to the console, but is not very convenient. Are there plans to introduce something more advanced at some point in the future?
Only thing I'd wish is for it to be ported to Windows and be 100% compatible with my existing scripts. ;)
It shows off a tiny bit of what you can do with Hammerspoon:
- window and app management
- keyboard shortcuts for common apps (eg. hyper+T for text editor, hyper+B for browser, hyper+S for shell)
- if you can code a tiny bit of Lua there's no need for apps like Spectacle, Rectangle, Moom, etc. because it's easy to position apps wherever you want. eg. hyper+L arranges my browser+editor+terminal in a standard layout, and I have other shortcuts to set apps to halves or thirds of the screen, or to another monitor.
- fuzzy-find popups (like Alfred/fzf) are built-in. I use it to choose audio input/output.
- a replacement for Caffeine (menubar icon to keep computer from going to sleep)
I have my "hyper" key bound to caps lock using Karabiner Elements (but it still works as a normal caps lock if you hold it for half a second). Here's that config: https://github.com/kbd/setup/blob/master/HOME/.config/karabi...Apple has a bit of documentation on scriptable key mapping:
https://developer.apple.com/library/archive/technotes/tn2450...
Here are the top ways I'm using it right now:
1) Hide/show apps similar to how iTerm lets you bind a hotkey to hide/show a terminal. I've got ctrl+space set to Vimcal, alt+space set to midnight.app (a time tracker I'm building), and ctrl+alt+space set to Things.
2) Start/stop playing my work playlist of lofi hiphop. I got tired of the friction around opening Spotify, going into my work playlist, hitting play, waiting several moments for the playlist to load, etc, so I downloaded a bunch of mp3s from YouTube and put them in ~/Music/work/. Now my work music is a single keyboard shortcut (semicolon+m) and a few miliseconds away.
3) Set up screen recording. There are a few things that need to happen before I start a screen recording (opening CamHead.app, setting my screen resolution, and showing the dock at a certain height so I can later crop the video to 16:9) and I have it all bound to a single hotkey (semicolon+r). I've got another hotkey set up to unset it (semicolon+e).
4) You may have noticed I'm using keyboard shortcuts with semicolon as a modifier key. That's done with Hammerspoon too! I've got an extra layer of hotkeys available to me to set up whatever else I can think of in the future. The code I wrote to use semicolon like this sometimes breaks if I try to type too many actual semicolons in a row but I usually rely on JS Beautify to add those for me.
Aka how everyone did it before Spotify took off.
But actually, I'm told time and again that Spotify has some APIs to control it—presumably when desktop apps are used (dunno for sure because don't use it myself). Personally I'd use Alfred for that over shortcuts.
I'm getting melancholic vibes of AutoHotKey reading the docs, which was arguably my first entry into professional programming. Knowing nothing about coding, I built a service desk automation back then — with (network file-) shared hotkeys and a real GUI, all in one single file... good times.
Anyway, ever since switching to MacOS more than a decade ago, I've always been searching for an AHK analog for those simple keystroke automations, text-based, with just enough of a glue language to hold it all together — Automator never quite cut it for me, after wielding the full power of AHK, it always felt too limited, rigid and clicky-colory.
Even though I don't have immediate use cases for it anymore, it makes me very happy that I know where to go back now!
you can set those in the keyboard settings in system preferences. i have used the text replacement tab a lot in the past. i used it to auto-insert smileys and text snippets on various platforms. i haven't used shortcuts much though. you always end up with complicated shortcuts so you don't conflict with your apps.
Translate (Requires Google Translate API key) https://github.com/pasiaj/Translate-for-Hammerspoon
Autocorrect: https://github.com/nathancahill/Anycomplete
It’s easy to use and has great docs. Lua is fun to write. HS is a really nice project.
My MacOS automation is now my QMK keyboard calling Alfred workflows; I use Yabai for window management.
I admire Lua, but ran into some sharp edges learning to program in it. Still, one can get up to speed quickly if one knows other scripting languages.
Hammerspoon window management was deathly slow. Yabai is close to instantaneous.
I feel Hammerspoon's Lua is to macOS what elisp is to Emacs. You can use it to glue all sorts of wonderful things.
I wrote a bit about it here: https://xenodium.com/emacs-utilities-for-your-os (building my own Alfred/Quicksilver-like experience) and https://xenodium.com/cycling-window-layouts-via-hammerspoon (cycle through my preferred window layouts).
edit: typos
local function insertDB(db, linkval, value)
local url = tostring(linkVal)
local categ = tostring(value)
db:exec[=[
INSERT INTO bookmarks VALUES (NULL,`url`,`categ`)
]=]
end
hs.hotkey.bind({"alt", "ctrl"}, "S", function()
db = hs.sqlite3.open('/dropbox/user/bookmarks.db')
local insert_stmt = assert( db:prepare("INSERT INTO
bookmarks VALUES (NULL, ?, ?)") )
local url = hs.pasteboard.getContents()
local tag, value = hs.dialog.textPrompt(url, "Please enter
category:");
if tag == 'OK' then
insert_stmt:bind_values(url, value)
insert_stmt:step()
insert_stmt:reset()
-- insertDB(db, linkVal, value)
end
end)- Hazel for automated tasks - Mosaic for layout shortcuts - Moom for layout grid drawing
Since discovering spacehammer, was able to use it to replace all those tools. Even had the opportunity to create one of my dream features: Can highlight any code sample in a browser or most other apps, press leader-t and select the tmux session to send the code, turning just about any page into a repl driven workflow.
A few years back I started contributing to spacehammer and refactored it to use a centralized config to make it easier for people to jump in and customize the menu and features.
Lua is ok to me but much prefer lisp languages like fennel, code feels more expressive and faster to produce using paredit lisp editing shortcuts in my editor.
Overall though I’m extremely grateful for Hammerspoon and if it ever stops working I might consider moving to Linux as my personal machine. I am able to chain key presses infinitely and categorize the different functions.
For example, I press “Caps Lock” + “Left shift” + “a” to open a global key chording menu, press “w” for my “window management” category which opens another key chord menu, then press “w” again to maximize my current window. I replace the final “w” with “m” to minimize, “p” to open the most recently used window in a stack of windows in an application. Not only that, these keys are case sensitive so that effectively doubles my space of usable infinite key chords.
Hammerspoon is so amazing for developer workflows after you put the time in.
https://github.com/nonissue/hammerspoon
Features include: - TOTP menubar app (that automatically types the code when clicked) - A menubar app for quickly changing screen resolution - A menubar sleep timer - Window management with convenient hot keys and undo functionality - Capslock rebinding to ESC when pressed alone, CTRL when pressed with other keys - A utility to allow you to both save a screenshot to disk AND have it copied to clipboard (AFAIK you can't do this natively in macOS).
There's other a bunch of other stuff, but those are the highlights. If you have any questions about it, please let me know! (email: andy@nonissue.org or open an issue on github).
- Mute my computer when I put it to sleep or when I change wifi networks
- Hyper key
- Mail.app menubar indicator
- Spotify menubar current song
- Shortcut to move mouse cursor to another monitor
- Window switcher that only lists apps in the current workspace
local cmdShift = {'cmd', 'shift'}
hs.hotkey.bind(cmdShift, 'm', function()
local app = hs.application.frontmostApplication()
for _, window in pairs(app:allWindows()) do
window:minimize()
end
end)
hs.hotkey.bind(cmdShift, 'u', function()
local app = hs.application.frontmostApplication()
for _, window in pairs(app:allWindows()) do
window:unminimize()
end
end)At least a few years ago, OS X's window management when plugging/unplugging external monitors was pretty bad.
Thanks to Hammerspoon, I don't have to think about it at all - I plug in monitors when I want to and all my windows resize and move themselves based on rules I defined.
It means stepping away from my desk or coming back to it is a no-brainer.
Maybe it's not needed these days, but it sure was a lifesaver back when I first adopted it.
My config, if people are interested:
https://github.com/NateEag/dotfiles/blob/master/src/.hammers...
I'd love to have one config that delivers the same workflow for my macos and my Debian system.
Maybe it's a nobrainer with a simple shell script, I haven't looked into it yet myself.
Thanks!