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

Send Growl notifications to Macs from Linux boxes UNIX
There is a way of sending messages to Growl running on a Mac OS X machine from any Unix machine with the standard X11 tools. You do not need to install anything on the Unix machine, just use the xkbbell command.

In short, you need to first install growlnotify on the Mac. You then need a configuration file, xkbevd.cf, with the following content:
Bell()  shell "/usr/local/bin/growlnotify --message \"$(name)\" --appIcon X11; true "
Start the X11 server, then start the xkbevd daemon (again on the Mac) pointing to the configuration file you just created (xkbevd -cfg xkbevd.cf -bg). You can then call the command xkbbell on the Unix machine to generate a Growl notification on the Mac. For example, xkbbell "lasers offline". There are detailed instructions and notes on my blog, for those who'd like more information on how this works.

[robg adds: I haven't tested this one.]
    •    
  • Currently 2.36 / 5
  You rated: 4 / 5 (11 votes cast)
 
[20,133 views]  

Send Growl notifications to Macs from Linux boxes | 6 comments | Create New Account
Click here to return to the 'Send Growl notifications to Macs from Linux boxes' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Send Growl notifications to Macs from Linux boxes
Authored by: mmnw on Aug 13, '09 11:58:56AM
Sounds awful complicated to me. There's a lot of overhead on the Mac, you have to start the X-Server, install growlnotify and have the xkbevd daemon running.
Why don't you just activate the networking protocol of Growl itself? There are several solutions available for Linux boxes to send messages to growl. Most of them don't require to install software. They usually just need a scripting engine, PHP, Perl or Python...
Good starting point is here:
http://growl.info/documentation/developer/protocol.php
(Go to the bottom, check the links. If you click through, you will also find solutions in perl)

I am using the PHP implementation for a while now with my linux box...

[ Reply to This | # ]
Send Growl notifications to Macs from Linux boxes
Authored by: wiesmann on Aug 14, '09 12:23:47AM

I'm using this because I use X11 anyways, and the Mac I'm connecting from does not have a fixed IP address. Not to mention that this avoids opening a port on the Mac, as everything goes over the ssh tunnel.



[ Reply to This | # ]
Send Growl notifications to Macs from Linux boxes
Authored by: baba on Aug 17, '09 09:45:58AM
I can't recall where I found this or how much I altered it, but it's useful especially when running long processes. I can just minimize the terminal window and wait for growl to let me know it's done.

#!/usr/bin/sh
# Run any commands as entered
# Report output to remote machine via growl.

$*
myDesktop='foo.bar.edu'
status=$?
condition=""
msg="$PWD: \n"`echo "$*"`

if [ $status -eq 0 ]; then
    condition="Finished"
    else
    condition="**Error**"
fi

title=`echo "$HOSTNAME: $condition"`
# growl errors to dev/null
echo $msg | ssh $myDesktop /usr/local/bin/growlnotify -t "$title" 2> /dev/null



[ Reply to This | # ]
Send Growl notifications to Macs from Linux boxes
Authored by: baba on Aug 17, '09 09:47:50AM

(That does reqire having ssh keypairs set up, by the way.)



[ Reply to This | # ]
Send Growl notifications to Macs from Linux boxes
Authored by: bluehz on Aug 18, '09 11:21:59AM
Yeah sounds like a LOT of overhead for simple growl notifications. I modified a php implementation from here http://the.taoofmac.com/space/Projects/netgrowl.php on my Ubuntu box.
#!/usr/bin/php -q
# netgrowl.php from here http://the.taoofmac.com/space/Projects/netgrowl.php
<?php

$ip = $argv[1];
$title = $argv[2];
$msg = $argv[3];
$sticky = $argv[4];
#$szApp = "test";
#$szApplication = $argv[5];

define( 'GROWL_UDP_PORT', 9887 );
define( 'GROWL_PROTOCOL_VERSION', 1 );
define( 'GROWL_TYPE_REGISTRATION', 0 );
define( 'GROWL_TYPE_NOTIFICATION', 1 );

class GrowlRegistrationPacket { // {{{
  var $m_szApplication;
  var $m_aNotifications;
  var $m_szPassword;
  var $m_szData;

  function GrowlRegistrationPacket(
    $szApplication = growlnotify,
    $szPassword = "" ) {

    $this->m_szApplication  = utf8_encode($szApplication);
    $this->m_szPassword     = $szPassword;
    $this->m_aNotifications = array();
  } // GrowlRegistrationPacket

  function addNotification(
    $szNotification = "Command-Line Growl Notification",
    $bEnabled = True) {

    $this->m_aNotifications[$szNotification] = $bEnabled;
  } // addNotification

  function payload() {
    $szEncoded = $szDefaults = "";
    $nCount = $nDefaults = 0;
    foreach( $this->m_aNotifications as $szName => $bEnabled ) {
      $szName = utf8_encode( $szName );
      $szEncoded .= pack( "n", strlen($szName) ) . $szName;
      $nCount++;
      if( $bEnabled ) {
        $szDefaults .= pack( "c", $nCount-1 );
        $nDefaults++;
      }
    }
    $this->m_szData = pack( "c2nc2",
                            GROWL_PROTOCOL_VERSION,
                            GROWL_TYPE_REGISTRATION,
                            strlen($this->m_szApplication),
                            $nCount,
                            $nDefaults );
    $this->m_szData .= $this->m_szApplication . $szEncoded . $szDefaults;

    if( $this->m_szPassword )
       $szChecksum = pack( "H32", md5( $this->m_szData . $this->m_szPassword ) );
    else
       $szChecksum = pack( "H32", md5( $this->m_szData ));
    $this->m_szData .= $szChecksum;
    return $this->m_szData;
  } // payload
} // GrowlNotificationPacket }}}

class GrowlNotificationPacket { // {{{
  var $m_szApplication;
  var $m_szNotification;
  var $m_szTitle;
  var $m_szDescription;
  var $m_szData;

  function GrowlNotificationPacket(
    $szApplication = growlnotify,
    $szNotification =  "Command-Line Growl Notification",
    $szTitle = "Title",
    $szDescription = "Description",
    $nPriority = 0,
    $bSticky = False,
    $szPassword = "" ) {

    $this->m_szApplication  = utf8_encode($szApplication);
    $this->m_szNotification = utf8_encode($szNotification);
    $this->m_szTitle        = utf8_encode($szTitle);
    $this->m_szDescription  = utf8_encode($szDescription);

    $nFlags = ($nPriority & 7) * 2;
    if( $nPriority < 0 )
      $nFlags |= 8;
    if( $bSticky )
      $nFlags |= 256;
    $this->m_szData = pack( "c2n5",
                            GROWL_PROTOCOL_VERSION,
                            GROWL_TYPE_NOTIFICATION,
                            $nFlags,
                            strlen($this->m_szNotification),
                            strlen($this->m_szTitle),
                            strlen($this->m_szDescription),
                            strlen($this->m_szApplication) );
    $this->m_szData .= $this->m_szNotification;
    $this->m_szData .= $this->m_szTitle;
    $this->m_szData .= $this->m_szDescription;
    $this->m_szData .= $this->m_szApplication;
    if( $szPassword )
       $szChecksum = pack( "H32", md5( $this->m_szData . $szPassword ) );
    else
       $szChecksum = pack( "H32", md5( $this->m_szData ));
    $this->m_szData .= $szChecksum;
  } // GrowlNotificationPacket

  function payload() {
    return $this->m_szData;
  } // payload
} // GrowlNotificationPacket }}}

$s = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
#$p = new GrowlRegistrationPacket("PHP Notifier");
$p = new GrowlRegistrationPacket("$szApp");
$p->addNotification("Informational", false);
$p->addNotification("Warning");
$szBuffer = $p->payload();
socket_sendto( $s, $szBuffer, strlen($szBuffer), 0x100, $ip, GROWL_UDP_PORT );
$p = new GrowlNotificationPacket("$szApp", "Warning", "$title",
                                 "$msg", -2, "$sticky" );  //TRUE=sticky
$szBuffer = $p->payload();
socket_sendto( $s, $szBuffer, strlen($szBuffer), 0x100, $ip, GROWL_UDP_PORT );
socket_close( $s );
?>

This is a sample script to send a notification to another machine running growl:
!/bin/bash

# FILENAME: testgrowl

###########################################
# VARIABLES
###########################################
#
# $1 = $ip
# $2 = $title
# $3 = $msg
# $4 = $sticky
# $szApp = "test";

ip=$1

##########################################
# MAIN
##########################################

php -q ./netgrowl.php "$1" "$2" "$3" "$4"

Then to fire off a growl:

./testgrowl 192.1.2.3 "Growl Title" "Growl Msg"

Sticky and szApp (icon) are optional

[ Reply to This | # ]

Send Growl notifications to Macs from Linux boxes
Authored by: wiesmann on Sep 16, '09 12:45:43AM
I have written a binary program called xkbgrowl which does the same thing as this script, with a few new features.

[ Reply to This | # ]