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?
Launch app on click of a growl notification
754 Views Asked by Trcx At
2
There are 2 best solutions below
0

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.)
One thing you could do would be to pass a
--url
option togrowlnotify
.Picking up Vaz's example:
Note that I removed
-w
from the parameters as well as theopen
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 afile://...
string to the--url
,growlnotify
opens 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 withhttp://
. "google.com" or "www.google.com" won't work. The same goes for your filesystem structure, you have to provide something likefile:///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!