PushBullet & AutoHotkey

Helpful script writing tricks and HowTo's
User avatar
Delta Pythagorean
Posts: 424
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Equestria

Re: PushBullet & AutoHotkey

26 Aug 2017, 18:28

Alright, it's clearly established that this function can send a message, what about reading a message that was sent from another user?
User avatar
Delta Pythagorean
Posts: 424
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Equestria

Re: PushBullet & AutoHotkey

26 Aug 2017, 18:46

flyingDman wrote:I want to be able to do PB_Message := clipboard. If the clipboard content includes a `n or `r it throws an error (the other code I referred to does this well)
Sending a message with a new line can simply be done by switching out the `n to \n.
Similarly, you can do this to most (Not tested) other escape messages.
Hope this helps!
User avatar
flyingDman
Posts: 73
Joined: 29 Sep 2013, 19:01
Location: Burbank, California

Re: PushBullet & AutoHotkey

12 Sep 2017, 13:48

Thanks. That seems to be the same solution as tmplinshi provided.

It seems that you have an interest for Pushbullet. Have you (or anybody else) found how to push a file?
User avatar
joedf
Posts: 6693
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: PushBullet & AutoHotkey

12 Sep 2017, 16:41

API seems pretty straight forward
For a file (see lower on the page):
https://docs.pushbullet.com/#create-push
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 3.00 GHz, 16GB DDR4 3200 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
User avatar
Blackholyman
Posts: 1272
Joined: 29 Sep 2013, 22:57
Facebook: socialjsz
Google: +Jszapp
Location: Denmark
Contact:

Using PushBullet & AutoHotkey to send a file

14 Sep 2017, 07:30

Example of Pushing a file

Code: Select all

#Include CreateFormData.ahk ; https://gist.github.com/tmplinshi/8428a280bba58d25ef0b
#Include BinArr.ahk ; https://gist.github.com/tmplinshi/a97d9a99b9aa5a65fd20
#Include JSON.ahk ; https://github.com/cocobelgica/AutoHotkey-JSON/blob/master/JSON.ahk

image_path := "C:\Blue Cube.png"

PB_Token   := "...Pease enter your own..."
PB_Image_Name   := "Blue Cube.png"

JSON_Response := PB_PushUpload_request(PB_Token, PB_Image_Name)

JSON_Response_object := JSON.load( JSON_Response )

objParam := { "file": [image_path]}
CreateFormData(postData, hdr_ContentType, objParam)

Status := PB_PushUpload_formData(JSON_Response_object.upload_url, postData, hdr_ContentType)
if (Status != 204)
{
	msgbox % "Upload Error!"
	return
}

msgbox % PB_PushFile(PB_Token, "This is an image test", JSON_Response_object.file_name, JSON_Response_object.file_type, JSON_Response_object.file_url)
return

PB_PushUpload_request(PB_Token, PB_Image_Name)
{
	WinHTTP := ComObjCreate("WinHTTP.WinHttpRequest.5.1")
	WinHTTP.SetProxy(0)
	WinHTTP.Open("POST", "https://api.pushbullet.com/v2/upload-request", 0)
	WinHTTP.SetCredentials(PB_Token, "", 0)
	WinHTTP.SetRequestHeader("Content-Type", "application/json")
	PB_Body := "{""file_name"": """ PB_Image_Name """, ""file_type"": ""image/png""}"
	WinHTTP.Send(PB_Body)
	Result := WinHTTP.ResponseText
	Status := WinHTTP.Status
	return Result
}

PB_PushUpload_formData(PB_upload_url, PB_postData, PB_ContentType)
{
	WinHTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	WinHTTP.Open("POST", PB_upload_url, true)
	WinHTTP.SetRequestHeader("Content-Type", PB_ContentType)
	WinHTTP.Option(6) := False ; No auto redirect
	WinHTTP.Send(PB_postData)
	WinHTTP.WaitForResponse()
	Result := WinHTTP.ResponseText
	Status := WinHTTP.Status
	return Status
}

PB_PushFile(PB_Token, PB_Body, PB_file_name, PB_file_type, PB_file_url)
{
	WinHTTP := ComObjCreate("WinHTTP.WinHttpRequest.5.1")
	WinHTTP.SetProxy(0)
	WinHTTP.Open("POST", "https://api.pushbullet.com/v2/pushes", 0)
	WinHTTP.SetCredentials(PB_Token, "", 0)
	WinHTTP.SetRequestHeader("Content-Type", "application/json")
	PB_Body := "{""type"": ""file"", ""body"": """ PB_Body """, ""file_name"": """ PB_file_name """, ""file_type"": """ PB_file_type """, ""file_url"": """ PB_file_url """}"
	WinHTTP.Send(PB_Body)
	Result := WinHTTP.ResponseText
	Status := WinHTTP.Status
	return Status
}
Also check out:
[hr][/hr]The Monthly AutoHotkey Webinars

My Autohotkey Blog
:dance: [hr][/hr]
Guest

Re: PushBullet & AutoHotkey

22 Dec 2017, 13:07

Maybe someone come in handy ... Works without glitches.

Code: Select all

PB_PushNote( PB_Token, PB_Message, PB_Number, PB_SourceUserID, PB_TargetDivaceID )
{
    WinHTTP := ComObjCreate("WinHTTP.WinHttpRequest.5.1")
    WinHTTP.SetProxy(0)
    WinHTTP.Open("POST", "https://api.pushbullet.com/v2/ephemerals", 0)
    WinHTTP.SetCredentials(PB_Token, "", 0)
    WinHTTP.SetRequestHeader("Content-Type", "application/json")
    PB_Body := "{""push"": {""conversation_iden"": """ PB_Number """, ""message"": """ PB_Message """, ""package_name"": ""com.pushbullet.android"", ""source_user_iden"": """ PB_SourceUserID """, ""target_device_iden"": """ PB_TargetDivaceID """, ""type"": ""messaging_extension_reply""}, ""type"": ""push""}"
    WinHTTP.Send(PB_Body)
    Result := WinHTTP.ResponseText
    Status := WinHTTP.Status
    Return Status
}
downloaderfan
Posts: 20
Joined: 09 Jun 2017, 09:19

Re: PushBullet & AutoHotkey

11 Jan 2018, 13:12

Does anyone have the code for receiving notifications from other devices in order to trigger ahk scripts? i.e. I send a Pushbullet notification containing specific text from my Android phone to PC & that triggers the AHK script actions.
icolinb
Posts: 4
Joined: 27 Dec 2015, 12:47

Re: PushBullet & AutoHotkey

05 Feb 2018, 13:53

Hi, I have tried but failed, is there anyway that I can use Pushbullet script without getting the Response Msg windows from appearing with the status.

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 6 guests