Skip to content

Instantly share code, notes, and snippets.

@dmynerd78
Last active September 16, 2015 02:00
Show Gist options
  • Save dmynerd78/3c09fd064059885d2558 to your computer and use it in GitHub Desktop.
Save dmynerd78/3c09fd064059885d2558 to your computer and use it in GitHub Desktop.
Run this file to quickly change your Windows power plan! (Will not work if your power plan has consecutive spaces in it (example: ' ')) It's a bit messy. Sorry about that
import os, sys
power_plans_data = []
available_power_plans = {}
input("\033[1;41mNOTE: If any of your power plans has more than one space in the name this program will NOT work!\n"
"Hit enter to continue\033[0m ")
power_plans = os.popen("powercfg /list").read()
power_plans = power_plans.replace("\n", "").replace("Power Scheme", "").split("GUID: ")[1:]
print("Choose a plan (* = active plan):")
for plan in range(1, len(power_plans)):
power_plans_data = power_plans[plan].split(" ")
available_power_plans[plan] = [power_plans_data[1], power_plans_data[0]]
print("%s) %s" % (plan, power_plans_data[1]))
notTrue = False
while not notTrue:
answer = input("\nWhich power plan do you want to use? ")
try:
# Check if power plan is valid
chosen_plan = available_power_plans[int(answer)]
if "*" in chosen_plan[0].split(")")[1]:
print("That plan is already in use!")
else:
yaaaayloops = True
while yaaaayloops:
confirm = input("Are you sure you want to use the '%s' power plan? (y/N) " % chosen_plan[0])
if confirm.lower().startswith("y"):
set_plan = os.popen("powercfg /setactive %s" % chosen_plan[1]).read()
input("Successfully changed power plans. Hit enter to exit the program")
notTrue = True
yaaaayloops = False
elif confirm.lower().startswith("n"):
break
except:
print("'%s' is not a valid answer!" % answer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment