I whipped this up tonight. I will clean it up later and make documentation, but it “works”. Set the receiving Mac to Listen For Incoming Notifications, Allow Remote Application Registration, and no password.
[code]-- growlnotify.lua (place in /usr/lib/lua)
socket = require(‘socket’);
local GrowlNotify = {}
local Notification = {}
GrowlNotify.__index = GrowlNotify
Notification.__index = Notification
– Transmit a UDP packet to a given host and port.
local function sendMessage(message, host, port)
local s = socket.udp()
s:sendto(message, host, port)
s:close()
end
– Consrtuct a Growl Notifier object.
function GrowlNotify.new(app, host, port)
local o = {}
setmetatable(o, GrowlNotify)
o.app = app
o.host = host
o.port = port or 9887
return o
end
– Construct n Notifications for this Notifier, and send the registration
– packet to the registered server.
function GrowlNotify:register(…)
local result = {}
for i,v in ipairs({…}) do
local n = {}
setmetatable(n, Notification)
n.app = self.app
n.host = self.host
n.port = self.port
n.notification = v
table.insert(result, n)
end
local message = “”
message = message … “\001” – GROWL_PROTOCOL_VERSION
message = message … “\004” – GROWL_TYPE_REGISTRATION_NOAUTH
local l = self.app:len()
message = message … string.char(math.floor(l/256)) … string.char( l % 256 ) – app name length
message = message … string.char(#result) – nall
message = message … string.char(#result) – ndef
message = message … self.app
for i,n in ipairs(result) do
l = n.notification:len()
message = message … string.char(math.floor(l/256)) … string.char( l % 256 ) – notification length
message = message … n.notification
end
for i,n in ipairs(result) do
message = message … string.char(i-1) – default
end
sendMessage(message, self.host, self.port)
return unpack(result)
end
– Send a notification packet.
function Notification:notify(title, description, priority, sticky)
local message = “”
message = message … “\001” – GROWL_PROTOCOL_VERSION
message = message … “\005” – GROWL_TYPE_NOTIFICATION_NOAUTH
message = message … “\000”
local priorityByte = 0
if (priority ~= nil) then
local priorityBitfield = { 96, 112, 0, 16, 32 }
priorityByte = priorityBitfield[priority + 3]
end
if (sticky) then
priorityByte = priorityByte + 128
end
message = message … string.char(priorityByte)
l = self.notification:len()
message = message … string.char(math.floor(l/256)) … string.char( l % 256 ) – notification length
l = title:len()
message = message … string.char(math.floor(l/256)) … string.char( l % 256 ) – title length
l = description:len()
message = message … string.char(math.floor(l/256)) … string.char( l % 256 ) – description length
l = self.app:len()
message = message … string.char(math.floor(l/256)) … string.char( l % 256 ) – app name length
message = message … self.notification
message = message … title
message = message … description
message = message … self.app
sendMessage(message, self.host, self.port)
end
return[/code]
Use like this:
gn = require("growlnotify")
instance = gn.new("VeraGrowlNotifier", '192.168.77.88') -- Your Mac here.
notifier, notifier2 = instance:register("SampleNotification", "SampleNotification2") -- Example has two notifications, but any number >= 1 allowed.
notifier:notify("Sample Title", "Sample Description", 2, true) -- Send notification.