在Hammerspoon中,如何在启动时获得当前关注的应用程序名称?

时间:2017-12-06 15:49:51

标签: macos lua hammerspoon

我可以在用户使用以下代码切换焦点后获取应用程序名称:

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

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

但是 Hammerspoon初始化之后我就是这样appName

1 个答案:

答案 0 :(得分:2)

请参阅hs.application.frontmostApplication()功能:http://www.hammerspoon.org/docs/hs.application.html#frontmostApplication:)