在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
相关产品推荐
相关产品推荐

