Sign in to follow this  
Followers 0
AutoitNew94

Need Help Building Function

8 posts in this topic

#1 ·  Posted (edited)

I need some help building a function that watches for certain processes to start, and

certain folders or files to open and then runs another program when this occurs.

I started off doing...

While 1
If WinActive("TEST1") Then MsgBox(0,"","TEST1 Window Was Opened")
If WinActive("TEST2") Then MsgBox(0,"","TEST2 Window Was Opened")
If WinActive("TEST3") Then MsgBox(0,"","TEST3 Window Was Opened")

If ProcessExists("firefox.exe") Then MsgBox(0,"","FireFox Was Opened")
If ProcessExists("notepad.exe") Then MsgBox(0,"","NotePad Was Opened")

Sleep(100)
WEnd

...which is an obvious mess and only works if one of the folders or processes is open.

So, if Firefox is running and then TEST1 is opened it does not recognize that TEST1 was

opened until FireFox closes.

I found this script through this forum, and played with it a bit, but I am still new to

Autoit and have not been able to modify it to fit my needs.

Dim $aWins[4] = ['', 'notepad.exe', 'calc.exe', 'firefox.exe']
_WinWaitMultiProcess($aWins, 5)

Func _WinWaitMultiProcess($aArray, $nTime = 0)
    If IsArray($aArray) = 0 Then Return SetError(1, 0, 0)
    Local $iTimer = TimerInit()
    While 1
        Sleep(100)
        For $iCC = 1 To UBound($aArray) -1
            If ProcessExists($aArray[$iCC]) Then Return $aArray[$iCC]
        Next
        If $nTime And (TimerDiff($iTimer) / -1) >= $nTime Then Return SetError(2, 0, 0)
    WEnd
EndFunc

In short I need a function that runs an infinite loop watching for folders and processes and then runs a program every time that happens. I do not want the script to exit.

Thank you, any and all help is appreciated.

Edited by AutoitNew94

"You're not smart enough for me to open my inbox, so stop sending me mail."

Share this post


Link to post
Share on other sites



Hii,

what process you are looking for?

How do you detect the the folder stuff? Is it a window that appears? A title of a window?

How do you do that without Autoit?

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

autoitnew94,

You are not returning from the "if processexists" because of the msgbox (blocking function).

As for the folders, do a forum search on folder modification. There was recently a lengthly post regarding folder change detection.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Hii,

what process you are looking for?

How do you detect the the folder stuff? Is it a window that appears? A title of a window?

How do you do that without Autoit?

Mega

Hi Xenobiologist thank you for the reply.

I am looking for the process name so when Firefox.exe and or Notepad.exe etc... starts the script executes some other code.

The folders are detected by the window title name.

Thanks.


"You're not smart enough for me to open my inbox, so stop sending me mail."

Share this post


Link to post
Share on other sites

autoitnew94,

You are not returning from the "if processexists" because of the msgbox (blocking function).

As for the folders, do a forum search on folder modification. There was recently a lengthly post regarding folder change detection.

kylomas

Thank you for the reply kylomas I just found the post. There are a few things within the post for other parts of the script that present themselves useful for the creation deletion and modifying of files which I will add to this topic.

Again thank you.

Could you give an example of returning from msgbox box while it is still open.

This I am searching now.


"You're not smart enough for me to open my inbox, so stop sending me mail."

Share this post


Link to post
Share on other sites

autoitnew94,

msgbox has a timeout parm (see doc). I find it way more convenient to use consolewrite for debugging messages.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

autoitnew94,

msgbox has a timeout parm (see doc). I find it way more convenient to use consolewrite for debugging messages.

kylomas

kylomas,

Thank you again.

So question I have now is in this script how am I to exit the While loop correctly

I tried messing around with the EndLoop, and for obvious reasons this script

does not work properly but something along these lines, and preferably built

into a functions, again thank you.

While 1
Sleep(100)
If WinActive("TEST1") Then 
    Run("calc.exe")
ElseIf WinActive("TEST2") Then
    Run("notepad.exe")
    EndIf
WEnd

"You're not smart enough for me to open my inbox, so stop sending me mail."

Share this post


Link to post
Share on other sites

autoitnew94,

use "exitloop" to leave loop or "exit" to terminate script. These depend on some logical condition that you determine based on your app.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
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
Sign in to follow this  
Followers 0