Skip to content

Instantly share code, notes, and snippets.

@juanpabloaj
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanpabloaj/5539f62da9b384de5158 to your computer and use it in GitHub Desktop.
Save juanpabloaj/5539f62da9b384de5158 to your computer and use it in GitHub Desktop.
watch files and push notification with pushbullet and powershell v2
$folder = 'c:\path\to\file'
$filter = '*.*'
$fsw = New-Object IO.FileSystemWatcher $folder, $filter
$fsw.IncludeSubdirectories = $true
$fsw.NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'
$onChanged = Register-ObjectEvent $fsw Changed -SourceIdentifier FileChanged -Action {
$name = $Event.SourceEventArgs.Name
$path = $Event.SourceEventArgs.FullPath
$user = "pushbullet_token"
$url = "https://api.pushbullet.com/v2/pushes"
$title = $path
Add-Type -AssemblyName System.Web
$title = [System.Web.HttpUtility]::UrlEncode($title)
$data = "type=note&title=" + $title + "&body=body"
$webclient = new-object System.Net.WebClient
$webclient.Credentials = new-object System.Net.NetworkCredential($user, "")
$result = $webclient.UploadString($url, "POST", $data)
}
#Unregister-Event FileChanged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment