
つうことで。
Prowlって何でもpush notificationできて便利なんですよーっていう記事です。
ここのところRubyつかってnotificationしてましたが、今回はWindowsのPowerShellを使ってみます。
というのも TVRock っていう録画マネージャアプリケーションがWindowsで、こいつの録画開始と終了をpushしてみたかったというだけなんですが。
そこで、Windowsで最も楽にscriptingできるのはなんだっていったらWSHかPowerShellなわけで。
まぁここは.NETのクラスライブラリがつかえるPowerShellにしてみましょう、と。
書いたコード
$state = $args[0]無駄に変数使ってるけどこれだけ。
$title = $args[1]
$url = "https://prowl.weks.net/publicapi/add"
$apikey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$data = New-Object System.Collections.Specialized.NameValueCollection
$data.add("apikey", $apikey)
$data.add("application", "TVRock")
$data.add("event", $state)
$data.add("description", $title)
$wc = New-Object System.Net.WebClient
$res = $wc.UploadValues($url, $data)
$wc.Dispose()
WebClient は勝手にUTF-8にしてくれるので何もしなくていいんですなぁ。
TVRockの設定

もうひとつ重要なのが、PowerShell で not-signed なスクリプトを実行できるようにしておかなくてはならない。
PS> Set-ExecutionPolicy RemoteSignedx64環境の場合はTVRockが32bitなので32bitのpowershell.exeで実行しておくこと。
詳細はget-help about_signingで。
こんな感じで、録画待機に入るとPush。さらに終了時にPush。
特定のアプリケーションやサービスに限定されずに Push Notification を利用できるのはいいですな。
0 コメント:
Post a Comment