单击咆哮通知即可启动应用程序

发布于 2024-12-02 20:19:57 字数 100 浏览 3 评论 0原文

使用 bash/shell 脚本,我有咆哮通知,告诉我何时登录尝试失败,并在咆哮通知中显示坐在计算机前的人的图片。有没有办法可以使用growlnotify启动预览以在单击通知时显示图片?

Using bash/shell scripting I have growlnotify telling me when there was a failed login attempt, and displaying the a picture of whoever was sitting in front of the computer in a growl notification. Is there a way that I can use growlnotify to launch preview to display the picture when the notification is clicked?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痞味浪人 2024-12-09 20:19:57

您可以做的一件事是将 --url 选项传递给 growlnotify

采用 Vaz 的示例:

(
  # load some cat pics... I promise they are actually cat pics but
  # I don't promise they won't go link-dead since I linked to google image caches
  # or something.
  img1=/tmp/catpic1; curl -L bit.ly/16IRub3 > $img1
  img2=/tmp/catpic2; curl -L bit.ly/XUCzHW > $img2

  # schedule growls... replace this of course with whatever
  # actually sends your growls
  for i in $img1 $img2; do
    ( growlnotify -s -m "oh noes $i" --image $i --url "file://ABSOLUTE_PATH/$i" ) &
    sleep 4
  done
)

请注意,我从参数中删除了 -w随后的open命令。由于我们使用的是 --url,因此 growlnotify 会自行处理回调。您不需要暂停执行,此方法可能会解决 Vaz 暴露的多个通知的问题。通过将 file://... 字符串传递给 --urlgrowlnotify 在单击后会在系统默认应用程序中打开引用的文件通知。

最后的陷阱:只有当您向其传递以 http:// 开头的字符串时,--url 才会正确处理 url。 “google.com”或“www.google.com”将不起作用。文件系统结构也是如此,您必须提供类似 file:///Users/you/Pictures/cats.jpg 的内容。

这个功能从 1.4 版本开始就可以使用,但是,根据我的检查,man 中缺少它。

资料来源:
https://code.google.com/p/growl/issues/详情?id=341
https://groups.google.com/d/msg/growldiscuss/nUdYxOevkxI/ oYjxdhSEi98J

希望有帮助!

One thing you could do would be to pass a --url option to growlnotify.

Picking up Vaz's example:

(
  # load some cat pics... I promise they are actually cat pics but
  # I don't promise they won't go link-dead since I linked to google image caches
  # or something.
  img1=/tmp/catpic1; curl -L bit.ly/16IRub3 > $img1
  img2=/tmp/catpic2; curl -L bit.ly/XUCzHW > $img2

  # schedule growls... replace this of course with whatever
  # actually sends your growls
  for i in $img1 $img2; do
    ( growlnotify -s -m "oh noes $i" --image $i --url "file://ABSOLUTE_PATH/$i" ) &
    sleep 4
  done
)

Note that I removed -w from the parameters as well as the open command that followed. Since we're using --url, growlnotify handles the callback on its own. You don't need to pause the execution and this method will probably solve the issue Vaz has exposed for multiple notifications. By passing a file://... string to the --url, growlnotifyopens the referred file in the system's default application after clicking the notification.

A final gotcha: --url will only handle url's correctly if you pass it a string starting with http://. "google.com" or "www.google.com" won't work. The same goes for your filesystem structure, you have to provide something like file:///Users/you/Pictures/cats.jpg.

This feature has been available since version 1.4, but, from what I've checked, it's missing from the man.

Sources:
https://code.google.com/p/growl/issues/detail?id=341
https://groups.google.com/d/msg/growldiscuss/nUdYxOevkxI/oYjxdhSEi98J

Hope it helps!

游魂 2024-12-09 20:19:57

这是一种方法:这样做的

(
  # load some cat pics... I promise they are actually cat pics but
  # I don't promise they won't go link-dead since I linked to google image caches
  # or something.
  img1=/tmp/catpic1; curl -L bit.ly/16IRub3 > $img1
  img2=/tmp/catpic2; curl -L bit.ly/XUCzHW > $img2

  # schedule growls... replace this of course with whatever
  # actually sends your growls
  for i in $img1 $img2; do
    ( growlnotify -ws -m "oh noes $i" --image $i ; open -a preview $i ) &
    sleep 4
  done
)

主要问题是,如果出现多个通知,单击一个通知将导致所有阻止的growlnotify子shell解除阻止(一次打开所有图片)。由于某种原因,这似乎是咆哮的标准行为。这可能不是一个真正的问题,除非它的行为不如正确排队它们那样好(我尝试用一​​些递归子外壳作业控制疯狂来做到这一点,但我不认为 bash 会让我这样做。 .. 当然有一种更复杂的方法可以将它们实际排队。)

Here's one way to do it:

(
  # load some cat pics... I promise they are actually cat pics but
  # I don't promise they won't go link-dead since I linked to google image caches
  # or something.
  img1=/tmp/catpic1; curl -L bit.ly/16IRub3 > $img1
  img2=/tmp/catpic2; curl -L bit.ly/XUCzHW > $img2

  # schedule growls... replace this of course with whatever
  # actually sends your growls
  for i in $img1 $img2; do
    ( growlnotify -ws -m "oh noes $i" --image $i ; open -a preview $i ) &
    sleep 4
  done
)

The main problem with this is that if more than one notification comes up, clicking one will cause all the blocking growlnotify subshells to unblock (opening all the pics at once). This seems to be standard behaviour for growl for some reason. That might not really be an issue except it doesn't behave as nicely as it would if it queued them up properly (I tried to do this with some recursive subshell job control craziness but I don't think bash will let me do it... there's certainly a more involved way it could be done to actually queue them up.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文