auto-it - How may I access and interact with controls intelligently?

  • From: "Valiant on the laptop" <valiant@xxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Fri, 7 Dec 2007 11:44:04 -0500

Hi again.
I'm still messing with auto-it. I wrote a script to toggle the power skeems 
between max battery and always on. On execution, an auto-killing msg box 
appears stating either switching to max battery or switching to max 
performance. It then goes on to access run dialogue, types powercfg.cpl and 
hits enter. Finally, when power options dialogue appears, it will either hit 
end, for max battery, or it will type a, for always on, depending on which it 
wants to set. It works as a toggle, so one activation switches it, activate it 
again and it switches back. It uses a text file to figure out what it set the 
option to last time.  Here's the script.

If FileRead("power.txt") = "max"  Then
 MsgBox(1, "", "Switching to max performance", 1)
ElseIf FileRead("power.txt") = "min"  Then
 MsgBox(1, "", "Switching to max battery", 0.5)
Else
 MsgBox(1, "", "Switching to max battery", 0.5)
EndIf
Send("#r")
WinWait("Run")
Send("powercfg.cpl{enter}") ; 
WinWait("Power Options Properties")
If FileRead("power.txt") = "max"  Then
 FileDelete("power.txt")
 Send("a")
 FileWrite("power.txt", "min")
 Sleep("250")
 Send("{enter}")
ElseIf FileRead("power.txt") = "min"  Then
 FileDelete("power.txt")
 Send("{END}")
 FileWrite("power.txt", "max")
 Sleep("250")
 Send("{enter}")
Else
 FileDelete("power.txt")
 Send("{END}") ; press the end key to hopefully set combo box to max battery
 FileWrite("power.txt", "max") ; so on next execution it will know to set to 
always on
 Sleep("250") ; let user see what it was changed to
 Send("{enter}") ; close the dialogue
EndIf

My question is, i'm doing this very blindly, I want to make this script 
available to other people. What if they have another option available that 
begins with A, it could set it to that instead, and that might not be a good 
thing. Also, maybe max battery isn't at the end of the list. So, I want to be 
able to take a look at the combo box, manually set it to max battery by looking 
for it and highlighting it somehow, then be able to do the same for always on, 
etc. If I can read the combo box, I can get rid of the text file, I can just 
set the new option depending on what it was already set to. 

Finally, is there a sneaky way to move around in dialogues without having the 
dialogues show? It'd be slick to magically do that without zooming through the 
dialogues on screen, although that's pretty cool too. Finally, how come auto-it 
won't just run powercfg.cpl with it's run command? I have to activate the run 
dialogue in windows to get it done. ShellOpen doen't work either, same problem, 
it says it doesn't have a proper association, problem is, I don't need an 
association, I just need it to tell windows to fire up that file, maybe I could 
go to systempath\\system32 or what ever and activate it in there but heck hmm, 
naw, is there a way to run the file without worrying about associations?
cheers
Regards: 
Aaron T. Spears (valiant) valiant@xxxxxxxxxxxxx Website - 
http://aarontech.randylaptop.com Windows Live Messenger: a1t2s3_89@xxxxxxxxxxx 
- AOL IM: computeruser89 - skype: aarontech.valiant 
Beta Testing System Information - 
Alienware Area 5551m Notebook System 
Intel core 2 duo: 2.16ghz (4mb cash) - 2.0gb DDR2SDRAM 667mhz 
ATI Radion 128mb dedicated video, 80gb SATA 7,200 rpm hard drive 
Windows XP Professional Version 2002 Service Pack 2 - all up to date 

Other related posts: