Stickies
Technical Support >> Networking >> external notification when a stickie is received?
http://tomrevell.conforums.com/index.cgi?board=supportonewrodid&action=display&num=1510852535

external notification when a stickie is received?
Post by doubleu on Nov 16th, 2017, 11:15am

Hello all. I'm curious if there is any way to have some sort of external notification (like an email, instant message, or text message) when a new stickie is received? For example, I'm frequently away from my desk, and it would be extremely helpful to know that I've received a stickie when i'm away. Whether it's via some 3rd party scripting or something, i'm just curious if anyone had any ideas.
Re: external notification when a stickie is receiv
Post by eef on Nov 18th, 2017, 07:01am

I looked into it because of the new "messenger" app Telegram that allows easy linking with its api.

It is easy to get a event notification/trigger using stickies api when a sticky comes through the network.

When you send a sticky to a "Friend" and it fails you have the option of sending it as email.Unfortunately using the netsend command this email option does not seem to be triggered.

It means you have to create the code for sending an email after the network sticky is detected.

This cannot be a problem but i had not yet time to look into it but i guess it would only be a few lines of code .

This is the code for detecting a new network sticky on PC.

Code:
#SingleInstance
setworkingdir %A_ScriptDir%
TargetScriptTitle = ZhornSoftwareStickiesMain
DetectHiddenWindows On
SetTitleMatchMode 2
WinGet, HA , ID, %A_ScriptName%


OnMessage(0x4a, "Receive_WM_COPYDATA")  
StringToSend=do register
IDc:=40
Send_(StringToSend,IDc)
return


send_notification:
StringToSend=do netsend %sid% address onlyemail ; Friend name with only valid email adress
IDc:=40
Send_(StringToSend,IDc)
MsgBox, 4,,notify sticky %sid%,4
return

esc::exitapp


Receive_WM_COPYDATA(wParam, lParam)
{
		Global datastring ,sid ,edit2 ,l
		ID                := NumGet(lParam + 0)
		len               := NumGet(lParam + A_PtrSize)
    StringAddress     := NumGet(lParam + 2*A_PtrSize)
  
    VarSetCapacity(CopyOfData, len,0)
    CopyOfData:= StrGet(StringAddress,len,"cp0")

ifinstring,CopyOfData,will send
msgbox ,4,, %copyofdata%,4

ifinstring,CopyOfData,network
{
sid:=regexreplace(CopyOfData,".*network (\w+)$","$1")
settimer,send_notification,-20
}

return true
}

Send_(StringToSend,IDc)
{
global TargetScriptTitle


    DetectHiddenWindows On
    SetTitleMatchMode 2 

    VarSetCapacity(CopyDataStruct, 3*A_PtrSize, 0)
     
    StringToSend=api %StringToSend%
    len := StrPutVar(StringToSend, StringToSend, "cp0")+1

    NumPut(IDc          , CopyDataStruct, 0) 
    NumPut(len , CopyDataStruct, 4)  
    NumPut(&StringToSend, CopyDataStruct, 8) 

    SendMessage, 0x4a, %A_ScriptHwnd%, &CopyDataStruct,, %TargetScriptTitle% 
    
  if (errorlevel="fail")
	{
  MsgBox SendMessage failed. Does the target application runs?
	
	} 
  
    return  
}

StrPutVar(string, ByRef var, encoding) 
{ 
    VarSetCapacity(var, StrPut(string, encoding) * ((encoding="UTF-16"||encoding="CP1200") ? 2 : 1)) 
    return StrPut(string, &var, encoding) 
}





 


Re: external notification when a stickie is receiv
Post by eef on Nov 18th, 2017, 08:52am

Here is a basic version with email code included , you need to adapt the password and username of the gmail account if you want to try it. ( tested on win10 pro using ahk version 1.1.26.01)

The script is paused when started ( trayicon red) to unpause use hotkey ctrl+alt+p or use the traymenu option pause.

I am still looking for an easier interface that makes it much clearer when the script is active but for the moment i just test this for a few days.

Gmail gave a warning that a less secure app was using the account i had to agree to using it anyway :)

update after testing it:



Code:
#SingleInstance
setworkingdir %A_ScriptDir%
TargetScriptTitle = ZhornSoftwareStickiesMain
DetectHiddenWindows On
SetTitleMatchMode 2
WinGet, HA , ID, %A_ScriptName%

OnMessage(0x4a, "Receive_WM_COPYDATA")  
StringToSend=do register
IDc:=40
Send_(StringToSend,IDc)

pause
return


^!p::pause


send_notification:

StringToSend=get desktop %sid% title
IDc:=40
Send_(StringToSend,IDc)
title:=CopyOfData
SendGmail("sticky received " title,"mygmailname@gmail.com") ; set correct email adress
MsgBox, 4,,notify sticky %sid%,4
return

esc::exitapp


SendGmail(message,emailto){	
	pmsg := ComObjCreate("CDO.Message")
	pmsg.From := """stickies"" <myPCemail@gmail.com>"
	pmsg.To := emailto
	pmsg.Subject := "Notification"
	pmsg.TextBody := message
	
	fields := Object()
	fields.smtpserver := "smtp.gmail.com"
	fields.smtpserverport := 465
	fields.smtpusessl := True
	fields.sendusing := 2
	fields.smtpauthenticate := 1
	fields.sendusername := "myemail@gmail.com" ; set correct name
	fields.sendpassword := "mypassword"        ; set correct password
	fields.smtpconnectiontimeout := 60
	
	schema := "http://schemas.microsoft.com/cdo/configuration/"
	pfld := pmsg.Configuration.Fields
	For field,value in fields
		pfld.Item(schema . field) := value
	pfld.Update()
	pmsg.Send()
	pmg.Close
}


Receive_WM_COPYDATA(wParam, lParam)
{
		Global CopyOfData ,sid 
		ID                := NumGet(lParam + 0)
		len               := NumGet(lParam + A_PtrSize)
    StringAddress     := NumGet(lParam + 2*A_PtrSize)
  
    VarSetCapacity(CopyOfData, len,0)
    CopyOfData:= StrGet(StringAddress,len,"cp0")

ifinstring,CopyOfData,will send
msgbox ,4,, %copyofdata%,4

ifinstring,CopyOfData,network
{
sid:=regexreplace(CopyOfData,".*network (\w+)$","$1")
settimer,send_notification,-20
}

return true
}

Send_(StringToSend,IDc)
{
global TargetScriptTitle


    DetectHiddenWindows On
    SetTitleMatchMode 2 

    VarSetCapacity(CopyDataStruct, 3*A_PtrSize, 0)
     
    StringToSend=api %StringToSend%
    len := StrPutVar(StringToSend, StringToSend, "cp0")+1

    NumPut(IDc          , CopyDataStruct, 0) 
    NumPut(len , CopyDataStruct, 4)  
    NumPut(&StringToSend, CopyDataStruct, 8) 

    SendMessage, 0x4a, %A_ScriptHwnd%, &CopyDataStruct,, %TargetScriptTitle% 
    
  if (errorlevel="fail")
	{
  MsgBox SendMessage failed. Does the target application runs?
	
	} 
  
    return  
}

StrPutVar(string, ByRef var, encoding) 
{ 
    VarSetCapacity(var, StrPut(string, encoding) * ((encoding="UTF-16"||encoding="CP1200") ? 2 : 1)) 
    return StrPut(string, &var, encoding) 
}





 

Re: external notification when a stickie is receiv
Post by doubleu on Nov 21st, 2017, 09:41am

works like a charm! thank you so much, eef!

Jan 16th 2018 edit: I have no proof, but it appears as though the Meltdown/Spectre windows update patch causes this to stop working. If this isn't the case for you, that's great, but in my specific case, when I uninstalled KB4056892 (Meltdown/Spectre patch for Windows 10 1709) it began working again. I am not looking more into the situation at this time.
Re: external notification when a stickie is receiv
Post by eef on Jan 16th, 2018, 02:32am

Quote:
looks like the Meltdown/Spectre windows update patch causes this to stop working.


You can use any another mailserver even an old pop without authentication because you are sending not reading or accessing your gmail account.

I tried it using 15 year old login data and the server still worked but you have to set the appropriate port and authentification (for POP port 25 no and authentification).

Do you have concrete evidence that the update is responsible?It could be more stringent requirements from gmail server,you already had to allow less save apps to have the code working with gmail.

Best regards,

BTW can you send email using stickies ,Tom just mentioned having a sendto api addition but i thought it would be unnecessary undecided