DEV Community

Discussion on: Better shortcuts with Karabiner Elements and Hammerspoon

Collapse
 
neighneighneigh profile image
NeighNeighNeigh • Edited

Update:

Never mind, I have it working now! I accidentally missed out including the following at the top of my script:
local log = hs.logger.new('hammerspoon','debug') 😬


Hey Cristian, I'm very interested in the app launcher you've implemented here. The automatic hiding is genius!

I've ran into an issue though and am getting an error. Hoping you might be able to spare a moment to take a look?

This is the contents of AppLauncher.lua, which I am successfully loading into Hammerspoon via AppLauncher = require('AppLauncher') in my init.lua

-- open hide app
function openApp(name)
  local app = hs.application.get(name)

  log.i("open App")
  log.i(name)
  log.i(app)

  if app then
    if app:isFrontmost() then
      log.i("app hiding")
      app:hide()
    else
      log.i("app focusing ")
      app:mainWindow():focus()
    end
  else
    log.i("app launch ")
    hs.application.launchOrFocus(name)
  end
end


function reminders()
  openApp("Reminders")
end
hs.hotkey.bind({}, 'F14', reminders)
Enter fullscreen mode Exit fullscreen mode

But when I issue the shortcut key, I get the following error

ERROR:   LuaSkin: hs.hotkey callback: /Users/nathan/.hammerspoon/AppL2.lua:5: attempt to index a nil value (global 'log')
stack traceback:
    /Users/nathan/.hammerspoon/AppL2.lua:5: in function 'openApp'
    /Users/nathan/.hammerspoon/AppL2.lua:25: in function 'reminders'
Enter fullscreen mode Exit fullscreen mode