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



使用bash/shell脚本,我有growlnotify告诉我,当有一个失败的登录尝试,并在一个咆哮通知中显示谁坐在电脑前的照片。是否有一种方法,我可以使用growlnotify启动预览,以显示图片时,通知被点击?

您可以将--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://...字符串传递给--url, growlnotify在点击通知后打开系统默认应用程序中所引用的文件。

最后一个问题:--url只会正确处理url,如果你给它一个以http://开头的字符串。"google.com"或"www.google.com"都不能用。对于您的文件系统结构也是如此,您必须提供类似file:///Users/you/Pictures/cats.jpg的东西。

这个功能从1.4版开始就有了,但是,据我所知,man中没有这个功能。

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

希望有帮助!

有一种方法:

(
  # 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解除阻塞(一次打开所有图片)。出于某种原因,这似乎是咆哮的标准行为。这可能不是一个真正的问题,除非它的行为不像它将它们正确排队那样好(我试图用一些递归subshell作业控制疯狂来做到这一点,但我不认为bash会让我这样做……当然,还有一种更复杂的方法可以让它们排队)

最新更新