Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #cs ----------------------------------------------------------------------------
- AutoIt Version: 3.3.12.0
- Author: Michael Cavaleri
- michael@cavaleri.dk
- Script Function:
- This script will run once every 5 minute. You can easily change this to
- run more frequent or have it delayed some. I thought 5 minutes seemed
- like a decent amount of time to balance resource usage and effectivity.
- You will receive a notification every 5 minutes when your laptop is
- running low on battery.
- This script will check if your computer is connected to the internet.
- If this is the case, then it will check your current battery status.
- If the power level is 20% or less (this amount being easy to change),
- then it will fire a notification to your smartphone or tablet or whatever
- device you are hooking it up to on PushBullet.
- The script will only fire a notification, if your laptop is not hooked
- up to a power source. By default, it will fire a notification to all of
- your devices on PushBullet. However, you can change it to a single device
- by changing $vSendToAll to False and entering your Device ID in $vDeviceID
- Instructions:
- 1. Press CTRL+F and search for "change these variables".
- 2. Change each variable to fit your needs.
- 3. Press F7 to compile this script into an executable.
- 4. Run the executable to receive notifications.
- #ce ----------------------------------------------------------------------------
- ; Include the necessary libraries:
- #include <WinAPISys.au3>
- ; Change these variables
- $vAccessToken = "ACCESS TOKEN" ; You can find your access token in http://www.pushbullet.com/account
- $vTimer = 300000 ; This is the amount of time it waits between checking battery status. 1000 = 1 second.
- $vPowerPercentageAlert = 20 ; This is the power level percentage where you want to receive the notification.
- $vSendToAll = True ; Change this to False if you only want notifications on a single device.
- $vDeviceID = "" ; Change this to the ID of the device if you only want notifications on one devices.
- #region ### CREATE TRAY MENU ###
- Opt("TrayMenuMode", 3)
- Opt("TrayOnEventMode", 1)
- $iExit = TrayCreateItem("Exit")
- #endregion ### CREATE TRAY MENU ###
- TrayItemSetOnEvent($iExit, "Close")
- While 1
- If _IsInternetConnected() Then
- $vPowerStatus = _WinAPI_GetSystemPowerStatus()
- If $vPowerStatus[0] = 0 Then
- if $vPowerStatus[2] <= $vPowerPercentageAlert Then
- if $vSendToAll = True Then
- $sPD = '{"type": "note", "title": "Laptop Battery Low", "body": "Your laptop only has ' & $vPowerStatus[2] &'% power left."}'
- ElseIf $vSendToAll = False Then
- $sPD = '{"device_iden": "' & $vDeviceID & '", "type": "note", "title": "Laptop Battery Low", "body": "Your laptop only has ' & $vPowerStatus[2] &'% power left."}'
- EndIf
- $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
- $oHTTP.Open("POST", "https://api.pushbullet.com/v2/pushes", False)
- $oHTTP.setRequestHeader("Authorization", "Bearer " & $vAccessToken)
- $oHTTP.SetRequestHeader("Content-Type", "application/json")
- $oHTTP.Send($sPD)
- EndIf
- EndIf
- EndIf
- Sleep($vTimer)
- WEnd
- #Region ### The Functions ###
- Func Close()
- Exit
- EndFunc
- Func _IsInternetConnected()
- Local $aReturn = DllCall('connect.dll', 'long', 'IsInternetConnected')
- If @error Then
- Return SetError(1, 0, False)
- EndIf
- Return $aReturn[0] = 0
- EndFunc ;==>_IsInternetConnected
- #EndRegion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement