如何使用 hammerspoon CLI?

我想能够运行像hs -m foo -c bar -- baz这样的命令,并使用bar和/或baz运行一些代码。hs -h帮助信息说baz应该可以通过_cli._args_cli.args获得,但我找不到_cli的值在哪里。

这是我的代码:

local ipc = require('hs.ipc'local port

function fooHandler()
    print'Hello,World!')
end

port = ipc.localPort('foo',fooHandler)

hs -m foo -c bar -- baz的输出为:

-- Legacy mode enabled --

我确定有一个简单的答案,但我找不到它。

原文链接 https://stackoverflow.com/questions/69711165

点赞
stackoverflow用户9701238
stackoverflow用户9701238

虽然我无法弄清楚如何与本地端口一起使用它,但我能够弄清楚如何使用默认的远程端口。下面是代码:

require('hs.ipc')
function bar(arg)
  print("Hello from bar! The arg is ".. arg)
end

如果你运行 hs -c "bar('baz')", 你会得到以下输出:

Hello from bar! The arg is baz
2023-01-01 13:21:38