当作业/流程完成后,如何让iTerm终端通知我?

tru*_*ess 81 macos terminal iterm iterm2

通知中心通知是理想的,但是咆哮,弹跳底座,声音等也可以(或者如果这只能在Terminal.app中完成,我愿意转回).iTerm中某处有选项可以打开通知,还是我应该在终端的命令末尾键入内容?如果是后者,一旦进程开始就可以添加警报(例如,如果我意识到它将花费比我最初预期更长的时间,我猜不好).

Pas*_*lis 149

在已经运行的进程上通知

捷径: A或:

Edit -> Marks and Annotations -> Alerts -> Alert on next mark

幽灵般的眼睛!:iTerm真的会留意你的终端(在右上角).一旦命令完成,它将联系Notification Center.

为什么?

我们已经启动了命令.我们低估了完成所需的时间,我们不想取消它,我们拒绝坐下来观看它.比如brew update很久以后!

要求

iTerm:Shell集成:

iTerm2 -> Install Shell Integration

请注意,在重新启动iTerm2之前,集成不会显示通知.

  • 啊,不适用于`tmux` :( (9认同)
  • 这眼睛吓到我了!!(╯‵□′)╯︵┻⁄┻ (8认同)
  • 安装shell集成后你可能想要转到iTerm2 - > Preferences - > Profiles - > Terminal,向下滚动并取消选中"Show mark indicators",我不喜欢这个shell集成.如果您想要os通知而不是警报样式弹出窗口,您可能还需要编辑 - >标记和注释 - >警报 - >发布通知. (7认同)
  • @dwanderson您是否曾经使用过tmux?这会很有帮助 (3认同)
  • @Lucas 文档中有一行指出 shell 集成不适用于 tmux 或 screen https://iterm2.com/documentation-shell-integration.html (2认同)
  • @ShamalKarunarathne 您是否在通过 SSH 连接的计算机上安装了 shell 集成脚本? (2认同)

Mar*_*ell 32

您可以在任何命令之后添加以下任何一项,在命令和它之间使用分号:

afplay /System/Library/Sounds/Ping.aiff -v 2

osascript -e 'beep 3'

tput bel
Run Code Online (Sandbox Code Playgroud)

或者,如果您喜欢通知中心

osascript -e 'display notification "Lorem ipsum dolor sit amet" with title "Title"'
Run Code Online (Sandbox Code Playgroud)

您还可以在配置文件中创建别名,notify并在命令末尾添加该别名.所以,在您的登录配置文件中

alias notify="tput bel"
Run Code Online (Sandbox Code Playgroud)

然后

sleep 10; notify
Run Code Online (Sandbox Code Playgroud)

或者,如果您启动了命令并且它是"挂起",只需键入notify并命中Enter,它将notify在命令结束时运行您的别名,例如

sleep 20

# wait 5 seconds before realising this will take 20 seconds
notify<Enter>
Run Code Online (Sandbox Code Playgroud)


Far*_*lam 29

并且您始终可以使用该say命令.

通常当你在终端内运行一个很长的进程并希望得到更新时,你可以简单地使用这个命令说出像doneor error或者这样的东西bazinga.

mvn clean install; say done 
Run Code Online (Sandbox Code Playgroud)

此命令构建一个java spring应用程序,需要很长时间,并且done在该过程完成后会说出来.

  • 天啊,这不仅很有帮助,而且非常酷,而且是一种非常简单的方法。 (2认同)

baf*_*baf 15

iTerm2支持Growl通知.您可以在每个配置文件设置中打开它.

Preferences…- >中选择一个配置文件Profiles.然后在Terminal选项卡中有一个选项Enable Growl Notifications.

请记住还要iTermGrowl首选项中启用通知.

如果您想获得给定流程的通知,可以尝试进行试验Triggers.您可以在Advanced配置文件设置的选项卡中定义触发器 通过这种方式,您可以将Growl通知分配给流程的特定输出(regexp).

你可以这样做:

$ mycommand; echo "end-of-my-process"
Run Code Online (Sandbox Code Playgroud)

并将触发器连接到"我的进程结束"消息.

更新

iTerm2.com上阅读有关触发器的更多信息.


Leo*_*rdo 7

安装 iTerm2 shell 集成

curl -L https://iterm2.com/shell_integration/install_shell_integration_and_utilities.sh | bash
Run Code Online (Sandbox Code Playgroud)

执行您的命令并连接注意力应用程序,例如

./task && ~/.iterm2/it2attention once
Run Code Online (Sandbox Code Playgroud)

作业完成后,它会导致 iTerm 应用程序弹起其图标。

您还有其他关注选项:

$ .iterm2/it2attention -h
Usage:
  it2attention start
    Begin bouncing the dock icon if another app is active
  it2attention stop
    Stop bouncing the dock icon if another app is active
  it2attention once
    Bounce the dock icon once if another app is active
  it2attention fireworks
    Show an explosion animation at the cursor
Run Code Online (Sandbox Code Playgroud)


小智 6

有一个名为noti的OSS工具。

您可以轻松地安装它brew install noti并开始使用它,只需在命令前面加上notilike即可noti sleep 3


MaS*_*Sza 6

您还可以使用terminal-notifierwhich use mac os 系统通知。要通过 Home brew 安装它,只需:

$ brew install terminal-notifier
Run Code Online (Sandbox Code Playgroud)

然后,如果您想在工作/流程完成时显示通知,请使用以下内容

$ <your job/process command> && echo 'Completed' | terminal-notifier -sound default
Run Code Online (Sandbox Code Playgroud)

这个显示是这样的:

在此处输入图片说明

您还可以更改通知的声音和图标。github repo 中的更多信息:https : //github.com/julienXX/terminal-notifier