Advertisement
Guest User

Laptop Power Notification

a guest
Jun 8th, 2015
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 3.43 KB | None | 0 0
  1. #cs ----------------------------------------------------------------------------
  2.  
  3.  AutoIt Version: 3.3.12.0
  4.  Author:         Michael Cavaleri
  5.                  michael@cavaleri.dk
  6.  
  7.  Script Function:
  8.     This script will run once every 5 minute. You can easily change this to
  9.     run more frequent or have it delayed some. I thought 5 minutes seemed
  10.     like a decent amount of time to balance resource usage and effectivity.
  11.  
  12.     You will receive a notification every 5 minutes when your laptop is
  13.     running low on battery.
  14.  
  15.     This script will check if your computer is connected to the internet.
  16.     If this is the case, then it will check your current battery status.
  17.     If the power level is 20% or less (this amount being easy to change),
  18.     then it will fire a notification to your smartphone or tablet or whatever
  19.     device you are hooking it up to on PushBullet.
  20.  
  21.     The script will only fire a notification, if your laptop is not hooked
  22.     up to a power source. By default, it will fire a notification to all of
  23.     your devices on PushBullet. However, you can change it to a single device
  24.     by changing $vSendToAll to False and entering your Device ID in $vDeviceID
  25.  
  26.     Instructions:
  27.     1. Press CTRL+F and search for "change these variables".
  28.     2. Change each variable to fit your needs.
  29.     3. Press F7 to compile this script into an executable.
  30.     4. Run the executable to receive notifications.
  31.  
  32. #ce ----------------------------------------------------------------------------
  33.  
  34. ; Include the necessary libraries:
  35. #include <WinAPISys.au3>
  36.  
  37.  
  38. ; Change these variables
  39. $vAccessToken = "ACCESS TOKEN"  ; You can find your access token in http://www.pushbullet.com/account
  40. $vTimer = 300000                ; This is the amount of time it waits between checking battery status. 1000 = 1 second.
  41. $vPowerPercentageAlert = 20     ; This is the power level percentage where you want to receive the notification.
  42. $vSendToAll = True              ; Change this to False if you only want notifications on a single device.
  43. $vDeviceID = ""                 ; Change this to the ID of the device if you only want notifications on one devices.
  44.  
  45. #region ### CREATE TRAY MENU ###
  46. Opt("TrayMenuMode", 3)
  47. Opt("TrayOnEventMode", 1)
  48. $iExit = TrayCreateItem("Exit")
  49. #endregion ### CREATE TRAY MENU ###
  50.  
  51. TrayItemSetOnEvent($iExit, "Close")
  52.  
  53.  
  54. While 1
  55.    If _IsInternetConnected() Then
  56.       $vPowerStatus = _WinAPI_GetSystemPowerStatus()
  57.       If $vPowerStatus[0] = 0 Then
  58.          if $vPowerStatus[2] <= $vPowerPercentageAlert Then
  59.             if $vSendToAll = True Then
  60.                $sPD = '{"type": "note", "title": "Laptop Battery Low", "body": "Your laptop only has ' & $vPowerStatus[2] &'% power left."}'
  61.             ElseIf $vSendToAll = False Then
  62.                $sPD = '{"device_iden": "' & $vDeviceID & '", "type": "note", "title": "Laptop Battery Low", "body": "Your laptop only has ' & $vPowerStatus[2] &'% power left."}'
  63.             EndIf
  64.             $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
  65.             $oHTTP.Open("POST", "https://api.pushbullet.com/v2/pushes", False)
  66.             $oHTTP.setRequestHeader("Authorization", "Bearer " & $vAccessToken)
  67.             $oHTTP.SetRequestHeader("Content-Type", "application/json")
  68.             $oHTTP.Send($sPD)
  69.          EndIf
  70.       EndIf
  71.    EndIf
  72.    Sleep($vTimer)
  73. WEnd
  74.  
  75.  
  76. #Region ### The Functions ###
  77. Func Close()
  78.    Exit
  79. EndFunc
  80.  
  81. Func _IsInternetConnected()
  82.     Local $aReturn = DllCall('connect.dll', 'long', 'IsInternetConnected')
  83.     If @error Then
  84.         Return SetError(1, 0, False)
  85.     EndIf
  86.     Return $aReturn[0] = 0
  87. EndFunc   ;==>_IsInternetConnected
  88. #EndRegion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement