Change what closing the lid does

Get help with using AutoHotkey and its commands and hotkeys
markifi
Posts: 1
Joined: 01 Sep 2019, 07:30

Change what closing the lid does

01 Sep 2019, 07:48

I'd like to temporarily set the current power profile to do nothing when I close the lid of the laptop. I know this is possible from windows command line based on https superuser.com /questions/874849/change-what-closing-the-lid-does-from-the-commandline. Broken Link for safety What this simple script is trying, but fails to achieve is query the current power profile, find out the specific subgroup for said profile, find the subgroup's power setting for what the operating system should do when closing the lid, and set those to "do nothing" for both the charging states. Wait a bit, and set it back to "sleep". It doesn't work for some reason. Apologies for the unbroken lines, it's a work in progress. What did I miss?

Code: Select all

activeProfile =			% SubStr(ComObjCreate("WScript.Shell").Exec("cmd.exe /q /c powercfg -GETACTIVESCHEME").StdOut.ReadAll(), 20, 36)
activeProfileSubgroup =		% SubStr(ComObjCreate("WScript.Shell").Exec("Run, cmd.exe /q /k powercfg -Q %activeProfile% | find ""Power buttons and lid""").StdOut.ReadAll(), 16, 36)
activeProfilePowerSetting = 	% SubStr(ComObjCreate("WScript.Shell").Exec("Run, cmd.exe /q /k powercfg -Q %activeProfile% | find ""Lid close action""").StdOut.ReadAll(), 21, 36)
; I'm trying to get the result of a command line query into the variables, but while this
; works for activeProfile, it doesn't for the other two. I'm messing up the inverted commas
Run, powercfg -SETACVALUEINDEX %activeProfile% %activeProfileSubgroup% %activeProfilePowerSetting% 0
	;do nothing in the current power profile when I close the lid on charger
Run, powercfg -SETDCVALUEINDEX %activeProfile% %activeProfileSubgroup% %activeProfilePowerSetting% 0
	;do nothing in the current power profile when I close the lid off charger
Sleep, 10000
Run, powercfg -SETACVALUEINDEX %activeProfile% %activeProfileSubgroup% %activeProfilePowerSetting% 1
	;sleep in the current power profile when I close the lid on charger
Run, powercfg -SETDCVALUEINDEX %activeProfile% %activeProfileSubgroup% %activeProfilePowerSetting% 1
	;sleep in the current power profile when I close the lid off charger
; https superuser.com /questions/874849/change-what-closing-the-lid-does-from-the-commandline
Broken Link for safety

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, BNOLI, freespacing, pasqualedk, yogurtpixel and 206 guests