Hammerspoon: Question - Clear the console?

Created on 21 Sep 2016  路  5Comments  路  Source: Hammerspoon/hammerspoon

Is there a way or command to clear the Hammerspoon Console?

I'd love to be able to 'reset' the console each time I reload the Config.

Thoughts?

Most helpful comment

Thanks @latenitefilms

It was a bit of a head scratcher for me, but I eventually figured out what I was doing wrong. For anyone else who might benefit, here's the code I inserted into my init.lua to get a Clear button on the Console:

-- custom Console toolbar (adds Clear button)
local toolbar = require("hs.webview.toolbar")
local console = require("hs.console")
local image = require("hs.image")
console.defaultToolbar = toolbar.new("CustomToolbar", {
    { id="prefs", label="Preferences", image=image.imageFromName("NSPreferencesGeneral"), tooltip="Open Preferences", fn=function() hs.openPreferences() end },
    { id="reload", label="Reload config", image=image.imageFromName("NSSynchronize"), tooltip="Reload configuration", fn=function() hs.reload() end },
    { id="openCfg", label="Open config", image=image.imageFromName("NSActionTemplate"), tooltip="Edit configuration", fn=function() openConfig() end },
    { id="clearLog", label="Clear", image = hs.image.imageFromName("NSTrashEmpty"), tooltip="Clear Console", fn=function() console.clearConsole() end },
    { id="help", label="Help", image=image.imageFromName("NSInfo"), tooltip="Open API docs browser", fn=function() hs.doc.hsdocs.help() end }
  }):canCustomize(true):autosaves(true)
console.toolbar(console.defaultToolbar)

function openConfig()
  hs.open(hs.configdir .. "/init.lua")
end

All 5 comments

@latenitefilms, hs.console.clearConsole() ?

Perfect, thanks @junkblocker !

Sorry... I missed the hs.console section in the API documentation. My bad!

Still, a little toolbar button would be super nice to have...

Thanks @latenitefilms

It was a bit of a head scratcher for me, but I eventually figured out what I was doing wrong. For anyone else who might benefit, here's the code I inserted into my init.lua to get a Clear button on the Console:

-- custom Console toolbar (adds Clear button)
local toolbar = require("hs.webview.toolbar")
local console = require("hs.console")
local image = require("hs.image")
console.defaultToolbar = toolbar.new("CustomToolbar", {
    { id="prefs", label="Preferences", image=image.imageFromName("NSPreferencesGeneral"), tooltip="Open Preferences", fn=function() hs.openPreferences() end },
    { id="reload", label="Reload config", image=image.imageFromName("NSSynchronize"), tooltip="Reload configuration", fn=function() hs.reload() end },
    { id="openCfg", label="Open config", image=image.imageFromName("NSActionTemplate"), tooltip="Edit configuration", fn=function() openConfig() end },
    { id="clearLog", label="Clear", image = hs.image.imageFromName("NSTrashEmpty"), tooltip="Clear Console", fn=function() console.clearConsole() end },
    { id="help", label="Help", image=image.imageFromName("NSInfo"), tooltip="Open API docs browser", fn=function() hs.doc.hsdocs.help() end }
  }):canCustomize(true):autosaves(true)
console.toolbar(console.defaultToolbar)

function openConfig()
  hs.open(hs.configdir .. "/init.lua")
end
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Pancia picture Pancia  路  4Comments

asmagill picture asmagill  路  4Comments

agzam picture agzam  路  3Comments

jasonrudolph picture jasonrudolph  路  4Comments

lazandrei19 picture lazandrei19  路  4Comments