For you, a nice gaming (pc) script. All you gotta do is point out my flaws

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
gibenedek
Posts: 53
Joined: 20 Sep 2020, 19:51

For you, a nice gaming (pc) script. All you gotta do is point out my flaws

17 Apr 2021, 03:11

I mean, I feel like I havent been here in a while, so I guess thats pretty good. Dont know what it was but ive been on a role lately. I was looking through the run command...the most simple command really, aside from hotkeystrings. Yet somehow its always got some more to it.

So I read about the PID output, and it dawned on me that instead of closing 20ish startup apps when I want to play nioh on my $250, 2016, HP prodesk (I wont be playing anything more intensive, I assure you) I could simply remove all the programs from startup, and instead place a script in there that calls them.

But of course, I couldnt just do it the easy way. Im a coder, so I will settle for nothing less than NOT having to update that script every time I find a dinky new program. So....functions and vars and %a_index% and file appends. Would I rearn anything if I just wrote 7 lines of boring? Nope.

And im happy with it, I didnt get ANY help outside the handbook, and really had to think outside the box with what I DID know could work. So here it is. Either a cool new timesaver, or a decent Idea for you to perfect. But if youre that 2nd guy, I really just want to know where I could have gone better. I learned a lot about variable assignments using other variables and all that, but I cant imagine this is optimized.

I had it as winwait, but Im not sure if circle dock counts as a window and I was tired of guessing. UIt crashes 1/5 of the time anyway. Not to mention I want it so I dont have to edit...getting a title out of a variable? Nahh

Code: Select all



StartupApps_Run(){
Settitlematchmode, 2
PIDWin1 = NonExistant_File
PIDWin2 = NonExistant_File
PIDWin3 = NonExistant_File
PIDWin4 = NonExistant_File
PIDWin4 = NonExistant_File
PIDWin5 = NonExistant_File
PIDWin6 = NonExistant_File
PIDWin7 = NonExistant_File
PIDWin8 = NonExistant_File
PIDWin9 = NonExistant_File

1 = "Circledock"
2 = ClipboardHelpAndSpell
If 2 =
{
	Loopcount = 1
	Goto Loop
}
3 = NiftyWindows
If 3=
{
	Loopcount = 2
	Goto Loop
}
4 = Picpick
If 4 =
{
	Loopcount = 3
	Goto Loop
}
5 = Quicklinks
If 5 =
{
	Loopcount = 4
	Goto Loop
}
6 = Rainmeter - Light
If 6 =
{
	Loopcount =5
	Goto Loop
}
7 = Winlaunch
If 7 =
{
	Loopcount = 6
	Goto Loop
}
8 = 
If 8 =
{
	Loopcount = 7
	Goto Loop
}
9 = 
If 9 =
{
	Loopcount = 8
	Goto Loop
}


Loop:
loop, %loopcount%
{
   Run := %a_index%
Run, %run%.lnk,C:\[DATA] All Files\[S] Startup Programs, min, %pid%%a_index%
sleep 15000
		}


		
		Results:
PIDRecord =
(
1 %PIDWin1%
2 %PIDWin2%
3 %PIDWin3%
4 %PIDWin4%
5 %PIDWin4%
6 %PIDWin5%
7 %PIDWin6%
8 %PIDWin7%
9 %PIDWin8%
0 %PIDWin9%
)


PIDWin1 = %pid1%
PIDWin2 = %pid2%
PIDWin3 = %pid3%
PIDWin4 = %pid4%
PIDWin5 = %pid5%
PIDWin6 = %pid6%
PIDWin7 = %pid7%
PIDWin8 = %pid8%
PIDWin9 = %pid9%
PIDWin0 = %pid0%

Fileappend, %PIDRecord%, C:\[DATA] All Files\[S] Startup Programs\Current Session PIDs.txt
Return
}


StartupApps_Run()




gibenedek
Posts: 53
Joined: 20 Sep 2020, 19:51

Re: For you, a nice gaming (pc) script. All you gotta do is point out my flaws

17 Apr 2021, 03:16

Oh. And im aware that it doesnt append the actual PID. But im over it for the moment. Prolly an easy fix
User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: For you, a nice gaming (pc) script. All you gotta do is point out my flaws

17 Apr 2021, 06:19

An easy technique would be to store your program paths in a text file. Use Loop, Read (or StrSplit) to read the lines, and Process to see whether the process already exists. If it does not exist, then Run the program, and wait 500 ms.

Code: Select all

file = %A_ScriptDir%\runPrograms.txt
If !FileExist(file) {
 MsgBox, 48, Error, File not found. Aborting.`n`n%file%
 Return
} Else FileRead, ttext, %file%
For index, prog in StrSplit(ttext, "`n") {
 If !FileExist(prog := Trim(prog, "`r"))
  Continue
 SplitPath, prog, proc
 Process, Exist, %proc%
 If ErrorLevel ; Already running
  Continue
 Run, %prog%
 Sleep, 500
}
MsgBox, 64, Done, Done!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, DaveT1, Descolada, KolaBorat and 171 guests