In Hammerspoon how do I get the currently focused application name on startup?

2.4k Views Asked by At

I can get the application name after the user switches focus with the following code:

function applicationWatcher(appName, eventType, appObject)
  if (eventType == hs.application.watcher.activated) then
    print(appName)
  end
end

local appWatcher = hs.application.watcher.new(applicationWatcher)

But I'd like this appName right after hammerspoon initializes.

1

There are 1 best solutions below

0
On BEST ANSWER

See the hs.application.frontmostApplication() function: http://www.hammerspoon.org/docs/hs.application.html#frontmostApplication :)