test if script is not already running Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
zayntheboss
Posts: 15
Joined: 24 Feb 2019, 15:21

test if script is not already running  Topic is solved

24 Feb 2019, 15:31

Hi!
I was wondering if it was possible to make a script that will loop maybe 30 times, and test if it's already running.
If the script isn't running, then it should run the script once, but if the script is running, then it should wait 1000 ms before testing again.

Can someone please help me with this? Does it use IfWinNotExist?


Edit:

I wrote this, but it doesn't seem to work

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

Esc::ExitApp ; Exit script with Escape key

Loop, 300 {
If WinExist("bot.ahk") {
Sleep, 1000
}
If !WinExist("bot.ahk") {
run C:\Users\tgrid\OneDrive\Desktop\bot.ahk
}
}
return
zayntheboss
Posts: 15
Joined: 24 Feb 2019, 15:21

Re: test if script is not already running

24 Feb 2019, 16:38

Got it to work, but it's kinda ugly; you need to create a file and test if it exists:

Loop, 360 {
if FileExist("C:\Users\tgrid\OneDrive\Desktop\running.txt") {
Sleep, 1000
}
else {
break
}
}
MsgBox, Working

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 159 guests