Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A Unix shell script to work with Growl UNIX
I have written a Unix shell script to call Growl -- here's the source. My script is named growl, and I keep a copy in $HOME/bin. I generally use my Growl script to notify me when a long-running Unix script finishes. If you are imaginative, you could have a cron job that calls Growl when disk space is low:
#!/bin/sh
df -m / | awk '
    /Filesystem/ { next }
    200 > $4 { system("growl root only has " $4 "MB available") }
'
Or if a critical system has gone off-line:
#!/bin/sh
if ! ping -c 1 -t 10 critical.system.com; then
    growl critical.system.com is off-line
fi


One last example ... if some remote site is off-line, you could have a script that Growls when the site is back on-line:
#!/bin/sh
while ! ping -c 1 -t 2 remote.site.com
do
    sleep 60
done
growl remote.site.com is available
There are lots of things a Unix user/developer does not want to wait around for, but would like to know the moment it is available. Growl turns out to be a very nice tool that can satisfy this need. And yes, I know there are ways to do this using Automator, AppleScript, launchd, etc., but I'm a Unix developer and shell scripts are what come naturally to me.

[robg adds: I haven't tested this one.]
    •    
  • Currently 4.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
 
[32,453 views]  

A Unix shell script to work with Growl | 12 comments | Create New Account
Click here to return to the 'A Unix shell script to work with Growl' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A Unix shell script to work with Growl
Authored by: nother on Jun 08, '07 08:26:53AM

Nice! Thanks. I use Growl extensively in other apps and have been looking for something like this for use in Terminal. Great examples, too. Very good job.



[ Reply to This | # ]
A Unix shell script to work with Growl
Authored by: sceaga on Jun 08, '07 08:37:07AM

Why not use the provided "growlnotify" extra?

growlnotify documentation

Here is a list of it's command-line options:

$ growlnotify -help
Usage: growlnotify [-hsvwc] [-i ext] [-I filepath] [--image filepath]
                   [-a appname] [-p priority] [-H host] [-u] [-P password]
                   [--port port] [-n name] [-m message] [-t] [title]
                   [-A method]
Options:
    -h,--help       Display this help
    -v,--version    Display version number
    -n,--name       Set the name of the application that sends the notification
                    [Default: growlnotify]
    -s,--sticky     Make the notification sticky
    -a,--appIcon    Specify an application name  to take the icon from
    -i,--icon       Specify a file type or extension to look up for the
                    notification icon
    -I,--iconpath   Specify a file whose icon will be the notification icon
       --image      Specify an image file to be used for the notification icon
    -m,--message    Sets the message to be used instead of using stdin
                    Passing - as the argument means read from stdin
    -p,--priority   Specify an int or named key (default is 0)
    -d,--identifier Specify a notification identifier (used for coalescing)
    -H,--host       Specify a hostname to which to send a remote notification.
    -P,--password   Password used for remote notifications.
    -u,--udp        Use UDP instead of DO to send a remote notification.
       --port       Port number for UDP notifications.
    -A,--auth       Specify digest algorithm for UDP authentication.
                    Either MD5 [Default], SHA256 or NONE.
    -c,--crypt      Encrypt UDP notifications.
    -w,--wait       Wait until the notification has been dismissed.

Display a notification using the title given on the command-line and the
message given in the standard input.

Priority can be one of the following named keys: Very Low, Moderate, Normal,
High, Emergency. It can also be an int between -2 and 2.

To be compatible with gNotify the following switch is accepted:
    -t,--title      Does nothing. Any text following will be treated as the
                    title because that's the default argument behaviour



[ Reply to This | # ]
A Unix shell script to work with Growl
Authored by: fracai on Jun 08, '07 08:38:58AM

:shakes fist:

---
i am jack's amusing sig file



[ Reply to This | # ]
A Unix shell script to work with Growl
Authored by: fracai on Jun 08, '07 08:37:55AM
you should also check out growlnotify, a command line tool for posting notifications, provided as an extra with Growl
http://growl.info/documentation/growlnotify.php

---
i am jack's amusing sig file

[ Reply to This | # ]

A Unix shell script to work with Growl
Authored by: shemp9999 on Jun 08, '07 08:39:15AM
I'm confused. I've always used the growlnotify script that is an extra install in the growl dmg for my terminal-based script notifications.

http://growl.info/documentation/growlnotify.php

[ Reply to This | # ]
A Unix shell script to work with Growl
Authored by: shemp9999 on Jun 08, '07 08:41:11AM

oops, guess i took too long finding the URL...what they said!



[ Reply to This | # ]
A Unix shell script to work with Growl
Authored by: Anonymous on Jun 08, '07 11:19:40AM

Yeah, I'm a little confused myself. Did the poster not know about growlnotify? He seems to be using AppleScript via the Terminal to do all the functions that growlnotify already does.

If he redid all this work simply because he missed growlnotify's existence, well, ouch.

Really, though, I'd suggest this hint get pulled.



[ Reply to This | # ]
A Unix shell script to work with Growl
Authored by: jecwobble on Jun 08, '07 12:24:44PM

Or perhaps by leaving the hint with comments intact, others will look here first before attempted to recreate the wheel again.



[ Reply to This | # ]
A Unix shell script to work with Growl
Authored by: SeanAhern on Jun 08, '07 03:25:36PM

robg,

Please pull this hint. It appears to have been posted because the submitter was not aware of the exact same functionality (growlnotify) already bundled with growl.



[ Reply to This | # ]
A Unix shell script to work with Growl
Authored by: BobHarris on Jun 08, '07 07:14:06PM

Nope, didn't know about growlnotify.

As for deleting this hint. It does not bother me. But I would hope it is replaced by a growlnotify hint. Because I know I searched MacOSXHints for Growl hints, and didn't find growlnotify.

As for the pain of writing my own script, it was fun. I develop Unix software for a living, and writing shell scripts (even big ones) is how I make difficult tasks easy.

And besides i learned a lot about Growl by writing my own script and by submitting my script to MacOSXHints, I learned about growlnotify. So it is a Win/Win situation for me.

And thanks to all the replies about growlnotify. At the very least, the posting of my hint has given more visibility to growlnotify.

Bob Harris



[ Reply to This | # ]
A Unix shell script to work with Growl
Authored by: bozo_z_clown on Jun 09, '07 11:06:44AM
I have Growl on my system (Bob's shell script works a treat) but I don't have growlnotify (locate growlnotify returns nothing) so it's not included with every installation of Growl. It's possible I got Growl via some other application.

I wouldn't pull the hint, I'd just preface it with "If you don't have growlnotify and you want to call Growl from Terminal ...".

[ Reply to This | # ]

A Unix shell script to work with Growl
Authored by: mrturtle on Jun 10, '07 06:21:05PM
growlnotify is included in every download of growl, but you have to install it separately. From the website:
In your shell, cd to the directory on the Growl disk image containing growlnotify, and type ./install.sh. That script will install growlnotify to /usr/local/bin and the manpage to /usr/local/man.


[ Reply to This | # ]