Jump to content

Make Script Run Indefinitely?


Recommended Posts

Hello,

Can somebody give me some insight on how to keep my script running continuously.

E.g, I have some hotkeys set to perform bat commands.

But I don't want it to automatically close after they are performed.

Edit: Actually they don't even run because they are all functions and get skipped over.

So the script closes almost instantly.

Edited by JohnCleese

"I find it rather easy to portray a businessman. Being bland, rather cruel and incompetent comes naturally to me."

Link to comment
Share on other sites

Just put this in the last few lines of your script, or at the last part of whatever is the main part of the script:

While(1)
WEnd

This seems to be working well, but I don't know if it will break as I add more.

Anyways, thank you very much this seems to be just what I needed. >_<

"I find it rather easy to portray a businessman. Being bland, rather cruel and incompetent comes naturally to me."

Link to comment
Share on other sites

A lot of my scripts are to add functions to other programs.

The following is my template in these cases.

I use the script instead of calling the program directly and have the script call it. I then add whatever hotkeys and other stuff to watch for in the script. This also exits the script after the program closes.

BTW. I've always put a sleep in there with the while statement. I don't know if that's needed or not. I've always assumed that a sleep line would use less processing power then always checking a while statement that can never change.

also always make sure you have some way of exiting the script. Either my method here or hotkey. Unless of course the intention is to always run as long as the computer is on. I have a couple that do that too.

; -----  run some program  
If Not WinExists(' program win title ') Then
    Run('program path exe', '')
    WinWaitActive('prog name')
    Sleep(2000)

Else
    WinSetState('program ', '', @SW_SHOW)   ; if in tray, this will make it show.
    WinActivate('program ', '')             ; I've got some apss that need this too to come into focus.

EndIf
are_we_done('exe of program that shows in tskmgr', 5)                ; exe of prog, timeout in sec


; setup whatever else you need to interact with the program.



; at end of script.
While 1
    Sleep(30000)
WEnd




; watch for program close.
Func are_we_done($process_name2,$timout_value)
    Global $process_name = ''
    $process_name = $process_name2
    AdlibEnable("are_we_done_2", $timout_value * 1000)
EndFunc   ;==>are_we_done

Func are_we_done_2()
    $pid = ProcessExists($process_name)
    If $pid == 0 Then Exit
EndFunc
Link to comment
Share on other sites

Yeah. You should insert a Sleep there in between my While(1) loop, to skimp on unnecessary processing by your script.

Personally, I just use a long Sleep command as my main executing script when I want to make a HotKey script that I want to stick around for a while.

Edited by omikron48
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...