Skip to content

Instantly share code, notes, and snippets.

@Fazzani
Last active May 25, 2018 14:13
Show Gist options
  • Save Fazzani/bbdba296fe8174f29067b80c7bba9a47 to your computer and use it in GitHub Desktop.
Save Fazzani/bbdba296fe8174f29067b80c7bba9a47 to your computer and use it in GitHub Desktop.
pushbullet notification
#! "netcoreapp2.1"
#r "nuget: PushBulletSharp, 3.1.0"
//#############################################################################################################################
// dotnet script : pushbullet example
// example:
// Tinyurl api => http://tinyurl.com/api-create.php?url=http://scripting.com/
// dotnet script https://tinyurl.com/ya5chql8 -- o.tZCHwg4A9C124ba2tFiiZDf1SaHzxJzC test "message to phone" 1>&2 || echo "no"
//#############################################################################################################################
using PushbulletSharp;
using PushbulletSharp.Filters;
using PushbulletSharp.Models.Requests;
using PushbulletSharp.Models.Responses;
if(Args.Count() < 3 )
{
Console.WriteLine($"Example to use : {Environment.NewLine} dotnet script https://tinyurl.com/osx-pushbullet -- o.tZCHwg4A9C124ba2tFiiZDfs1sSaHzsxJsdzC test \"message to phone\"");
}
var token = Args[0];
var title = Args[1];
var message = Args[2];
var client = new PushbulletClient(token);
try
{
//If you don't know your device_iden, you can always query your devices
var devices = client.CurrentUsersDevices();
var device = devices.Devices.Where(o => o.Icon == "phone").FirstOrDefault();
if (device != null)
{
var request = new PushNoteRequest
{
Title = title,
Body = message
};
var response = client.PushNote(request);
Console.WriteLine($"{response.Iden}");
return response.Dismissed ? -1 : 0;
}
}
catch (System.Exception)
{
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment