The Only Text Expansion I've Ever Needed

September 12, 2020

I have really wanted to integrate text expansion tools like TextExpander and TypeIt4Me into my workflows for years, but after many trials, the only expansion I used consistently was transforming @date into today’s actual date.

When tweaking my setup earlier this year, I stopped using any text expansion and had Hammerspoon to insert the date at the active keyboard insert point / cursor.

The snippet binds a hotkey (Command-Option-Control-d) and when pressed, it gets today’s date and prints it at the keyboard. Add it to your init.lua. 1

The os.date function is very customizable - make the date print out in any format you prefer.

hs.hotkey.bind({"cmd", "alt", "ctrl"}, "d", function()  
  local dateString = os.date('%m-%d-%Y')
  hs.eventtap.keyStrokes(dateString)
end)  

  1. Make sure Hammerspoon accessibility is turned on. ↩︎