StormyNP Posted April 21, 2011 Posted April 21, 2011 I have seen some other mention of using Snarl For Windows with APIs. Here's a simple example of how to do Snarl notifications simply by opening a TCP/IP socket to it. Nothing extra needed.Snarl for Windows can be found here:Snarl's Temporary LinkI apologize for the extra functions, I was already trying to design something bigger. The basics though are very simple.This is my first posted script, constructive criticism appreciated!If there are any Growl for Windows examples, I'd love to see some as well.expandcollapse popup$snarl_ip = "127.0.0.1" $snarl_port = 9887 $snarl_command_type = "type=SNP#?version=1.0#?" $snarl_command_action_register = "action=register#?" $snarl_command_action_add_class = "action=add_class#?" $snarl_command_action_notification = "action=notification#?" $snarl_command_action_unregister = "action=unregister#?" $snarl_app = "app=AutoIt Script" $snarl_socket = -1 $snarl_class_detail = "Detailed notifications" $snarl_class_summary = "Summary notifications" $snarl_class_warnings = "Warning notifications" ; Example function shows how to register app to Snarl, create a few message classes/levels, and send messages to each. Example() Func Example() If ConnectToSnarl() <> 1 Then Return EndIf ; This would be more for an initial Setup with Snarl. You only need to run this once ; per application you want Snarl to know about. Otherwise, no need to keep running this. ;RegisterWithSnarl() ; Code to unregister (or you can just unregister app from Snarl's own App settings) ;UnRegisterWithSnarl() ; Let's test the messages and different message classes for the app! ; Note, a 0 for timeout makes the notification "Sticky" SnarlMessage( "test 1", "Hello World!", $snarl_class_detail, 10 ) SnarlMessage( "test 2", "Greetings!", $snarl_class_summary, 10 ) SnarlMessage( "test 3", "w00t!", $snarl_class_warnings, 10 ) Disconnect() EndFunc Func ConnectToSnarl() $rc = TCPStartup() If $rc <> 1 Then Return -1 EndIf $snarl_socket = TCPConnect( $snarl_ip, $snarl_port ) If @error Then MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error) Return -1 EndIf Return 1 EndFunc Func Disconnect() $rc = TCPShutdown() EndFunc Func SnarlMessage( $in_title, $in_text, $in_classnum, $in_timeout ) $msg = $snarl_command_action_notification & $snarl_app & "#?class=" & $in_classnum & "#?title=" & $in_title & "#?text=" & $in_text & "#?timeout=" & $in_timeout If SendToSnarl( $msg ) <> 1 Then Return -1 EndIf Sleep( 1500 ) EndFunc Func SendToSnarl( $in_msg ) TCPSend( $snarl_socket, $snarl_command_type & $in_msg & @CRLF ) If @error Then MsgBox( 4112, "Failure talking to Snarl", $in_msg ) Return -1 EndIf Return 1 EndFunc Func RegisterWithSnarl() ; register the application so it shows in Snarl tray Apps settings ; I find the Sleep delay is necessary to give the Snarl registration a chance to keep up $msg = $snarl_command_action_register & $snarl_app If SendToSnarl( $msg ) <> 1 Then Return -1 EndIf Sleep( 1500 ) ; add additional classes for the app so user has control over what messages they see ; I just added 3 different categories $msg = $snarl_command_action_add_class & $snarl_app & "#?class=" & $snarl_class_detail If SendToSnarl( $msg ) <> 1 Then Return -1 EndIf Sleep( 1500 ) $msg = $snarl_command_action_add_class & $snarl_app & "#?class=" & $snarl_class_summary If SendToSnarl( $msg ) <> 1 Then Return -1 EndIf Sleep( 1500 ) $msg = $snarl_command_action_add_class & $snarl_app & "#?class=" & $snarl_class_warnings If SendToSnarl( $msg ) <> 1 Then Return -1 EndIf Sleep( 1500 ) Return 1 EndFunc Func UnregisterWithSnarl() $msg = $snarl_command_action_unregister & $snarl_app If SendToSnarl( $msg ) <> 1 Then Return -1 EndIf Return 1 EndFunc
BOfH73 Posted December 4, 2015 Posted December 4, 2015 (edited) Hi there, exactly what i was looking for. Til now i sent the snarl message with a runline, the run command in AutoIt and the snarl_cmd.exe.I took your code and modified it to build the Snarl.au3, which you can include in your programs.I attached the Snarl.au3.In your Script include the Snarl.au3 with#Include <Snarl.au3>and send a message for example with_send_snarl("192.168.0.2","d","Titletext","Messagetext",timeout)d = detailed / s = summary / w = warningIf timeout isn´t set the default is 10 seconds I hope it is useful for you Snarl.au3 Edited December 7, 2015 by BOfH73
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now