2011-09-02 203 views
4

使用bash/shell脚本编制我已经不断地告诉我什么时候登录尝试失败,并在咆哮通知中显示坐在计算机前的任何人的图片。有没有办法让我可以使用growlnotify启动预览,以便在点击通知时显示图片?通过单击咆哮通知启动应用程序

+0

想用'-w'来阻止[growlnotify](http://growl.info/extras.php#growlnotify),直到用户响应,然后从脚本启动预览? –

+0

我认为这不会起作用,因为这会暂停脚本的运行,从而防止更多的图片被拍摄到其他失败的登录。 – Trcx

+0

当您检测到登录失败时,您可以为您的脚本生成新的进程/线程吗? –

回答

0

这里有一个办法做到这一点:

(
    # 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来解锁(在打开所有图片一旦)。出于某种原因,这似乎是咆哮的标准行为。这可能不是真正的问题,除非它的行为不如它正确排队它们那么好(我试图用一些递归子shell作业控制的疯狂做到这一点,但我不认为bash会让我这样做。 ..确实有更多的参与方式可以将它们排队。)

3

你可以做的一件事就是将--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 
) 

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

最后一个问题:--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=341 https://groups.google.com/d/msg/growldiscuss/nUdYxOevkxI/oYjxdhSEi98J

希望它能帮助!

相关问题