You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Hammerspoon中如何启动应用并传入自定义启动参数?

Hammerspoon 启动带自定义参数Chrome的解决方案

hs.application.open/hs.launchOrFocus/hs.urlevent.openURL等方法走的是macOS原生LaunchServices应用启动接口,不支持传递自定义命令行参数,因此需要直接调用Chrome二进制文件并传入参数实现需求。

方案1:使用hs.execute直接执行终端命令

和你本地终端执行的效果完全一致,配置简单:

-- 绑定 Option + Command + M 触发启动,可自行修改快捷键组合
hs.hotkey.bind({"cmd", "alt"}, "M", function()
    -- 替换为你自己的会议地址和配置文件名
    local execCmd = [[/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --app=https://meet.google.com/some-meeting-id --profile-directory='Profile 1' &]]
    hs.execute(execCmd)
end)
  • 命令末尾的&作用是让Chrome进程后台运行,不会阻塞Hammerspoon主线程
  • 配置文件名可在对应Chrome配置的地址栏输入chrome://version/,查看「个人资料路径」最后一段获取

方案2:使用hs.task更稳定地拉起进程

不需要处理shell转义问题,所有参数直接传递,兼容性更好:

hs.hotkey.bind({"cmd", "alt"}, "M", function()
    local chromeBinary = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
    local meetUrl = "https://meet.google.com/some-meeting-id" -- 替换为实际会议地址
    local profileName = "Profile 1" -- 替换为实际配置目录名

    hs.task.new(chromeBinary, nil, {
        "--args",
        "--app="..meetUrl,
        "--profile-directory="..profileName
    }):start()
end)

内容的提问来源于stack exchange,提问作者randulfir

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 01:15:07