command=r'system_profiler SPPowerDataType | grep -A3 -B7 "Condition"' import sys import subprocess process=subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) result=process.communicate()[0] def alert(arg): sys.stderr.write("%d%d%d" % (arg, arg, arg)) if "Normal" in result: print ("Normal") alert(0) elif "Replace Soon" in result: print ("Replace Soon: The battery is functioning normally but holds less charge than it did when it was new") alert(0) elif "Replace Now" in result: print("Replace Now: The battery is functioning normally but holds significantly less charge than it did when it was new. You can continue to use the battery until you replace it without harming your computer") alert(1) elif "Service Battery" in result: print ("Service Battery: The battery isn't functioning normally, and you may or may not notice a change in its behavior or the amount of charge it holds. Take your computer in for service. You can continue to use your battery before it's checked without harming your computer") print ("Critical!!!!") alert(1) else: print ("This is not MAC Laptop") alert(0)