-
Notifications
You must be signed in to change notification settings - Fork 47
/
Battery Charge Percentage.xml
33 lines (27 loc) · 1.26 KB
/
Battery Charge Percentage.xml
1
<?xml version="1.0" encoding="UTF-8"?><extensionAttribute> <displayName>Battery Charge Percentage</displayName> <displayInCategory>System Information</displayInCategory> <dataType>integer</dataType> <description>This attribute returns remaining charge percentage of the battery, if installed. This attribute applies to both Mac and Windows.</description> <scriptContentsMac>#!/bin/shmaxCapacity=`ioreg -r -c "AppleSmartBattery" | grep -w "MaxCapacity" | awk '{print $3}' | sed s/\"//g`currentCapacity=`ioreg -r -c "AppleSmartBattery" | grep -w "CurrentCapacity" | awk '{print $3}' | sed s/\"//g` result=$( echo "scale=4; ($currentCapacity / $maxCapacity) * 100" | bc | sed 's/\(.*\)../\1/' )echo "<result>$result</result>" </scriptContentsMac> <scriptTypeWindows>VBScript</scriptTypeWindows> <scriptContentsWindows>On Error Resume Next Dim objBatteriesDim strBatteries Set objBatteries = GetObject("winmgmts:").InstancesOf("Win32_Battery")i=0For each Battery in objBatteriesif i <> 0 thenstrBatteries = "<br>" & strBatteriesEnd IfstrBatteries = Battery.EstimatedChargeRemaining & strBatteries i=i+1NextWScript.Echo "<result>" & strBatteries & "</result>"</scriptContentsWindows></extensionAttribute>