简体   繁体   English

点击咆哮通知启动应用程序

[英]Launch app on click of a growl notification

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. 使用bash / shell脚本我告诉我何时登录尝试失败,并在咆哮通知中显示坐在计算机前面的人的照片。 Is there a way that I can use growlnotify to launch preview to display the picture when the notification is clicked? 有没有办法,我可以使用growlnotify启动预览,以便在点击通知时显示图片?

One thing you could do would be to pass a --url option to growlnotify . 你可以做的一件事是将--url选项传递给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. 请注意,我从参数以及随后的open命令中删除了-w Since we're using --url , growlnotify handles the callback on its own. 由于我们使用--urlgrowlnotify自己处理回调。 You don't need to pause the execution and this method will probably solve the issue Vaz has exposed for multiple notifications. 您不需要暂停执行,这种方法可能会解决Vaz为多个通知公开的问题。 By passing a file://... string to the --url , growlnotify opens the referred file in the system's default application after clicking the notification. 通过将file://...字符串传递给--urlgrowlnotify在单击通知后打开系统默认应用程序中的引用文件。

A final gotcha: --url will only handle url's correctly if you pass it a string starting with http:// . 最后一个疑难杂症: --url如果你传递开始用绳子将只处理URL的正确http:// "google.com" or "www.google.com" won't work. “google.com”或“www.google.com”无法使用。 The same goes for your filesystem structure, you have to provide something like file:///Users/you/Pictures/cats.jpg . 您的文件系统结构也是如此,您必须提供类似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 . 此功能已自1.4版本,但是,从我检查,它是从失踪man

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

Hope it helps! 希望能帮助到你!

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). 这个问题的主要问题是,如果出现多个通知,单击一个将导致所有阻止growlnotify子shell解除阻塞(一次打开所有图片)。 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.) 这可能不是一个问题,除非它的行为不如它正确地将它们排队好(我尝试用一​​些递归的子shell作业控制疯狂但我不认为bash会让我这样做。 ..当然有一种更为复杂的方式来实际排队。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM