hi,
On XP, I am trying to invoke a procedure whenever a new notepad is opened.
My procedures are as:
---------------------
OnEvent>WINDOW_OPEN,Untitled*,WF_TYPE,DoThis
SRT>DoThis
Ask>yss,res
END>DoThis
Wait>10
---------------------
After running the script, if I open the notepad, I could see no prompt window popping up. Please help me in resolving this.
Thanks in advance.
jiby
Invoking a subroutine when new window is opened
Moderators: Dorian (MJT support), JRL
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
WF_TYPE should be a numeric value being one of the WF_TYPE values (see the SetFocus help topic for a list of options).
Try this:
Note that once you open Notepad DoThis will keep firing because you have no provision in here to flag that we've already triggered. Note also the idle_loop. This is to simulate the script doing something otherwise it's just going to end. And waiting 10 seconds won't help as that 10 second wait will hold things up anyway. Hopefully the above will get you going where you want to go.
Try this:
Code: Select all
OnEvent>WINDOW_OPEN,Untitled*,1,DoThis
Label>idle_loop
Wait>0.02
Goto>idle_loop
SRT>DoThis
Ask>yss,res
END>DoThis
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
I had just typed this up when Marcus posted. It has the flag he mentioned and also another Onevent to close the script when Notepad is closed.
Code: Select all
Let>WF_TYPE=1
OnEvent>WINDOW_OPEN,Untitled*,WF_TYPE,DoThis
Let>DoThisFlag=0
SRT>DoThis
If>DoThisFlag=0
Ask>yss,res
OnEvent>WINDOW_NOTOPEN,Untitled*,WF_TYPE,Quit
Let>DoThisFlag=1
EndIf
END>DoThis
SRT>Quit
Exit>0
END>Quit
Label>Loop
Wait>0.01
Goto>Loop
Yes, I'd expect that. Look at the definition for OnEvent>WINDOW_OPEN in the Help File:jiby wrote:Is it possible to trigger "OnEvent" only when any NEW Window is opened. I tried,
OnEvent>WINDOW_OPEN,*,1,DoThis
When 4 windows are already opened before running this script, it is going to infinite loop. I was getting continuous "Confirm" popup window.
Notice it does not say it triggers "when the specified window opens" or "when the specified window first opens"... just... when it is open.Help File wrote:WINDOW_OPEN
Window_Title
WF_TYPE
Triggers when specified window is open.
Well, once it opens, it may be open for a long time... that OnEvent is going to keep firing over and over again and will continually keep firing until that window finally is closed.
Sidenote: Personally I think of and treat OnEvent>WINDOW_OPEN more like... "OnState">WINDOW_OPEN... because it keeps firing while the state of that window is "Open". This threw me at first because when I first saw the new OnEvent commands... I expected it would fire only once... when the window actually opened. Nope, that's not the way it works and once I knew that, things made sense again. I just mention this in case you were thinking the same way.
There is no OnEvent trigger you can use to tell you that a new specific window has just been opened though I think that would be a fine idea for a new EventType... maybe call it "WINDOW_JUST_OPENED" to remove any ambiguity? Anyway, we do have OnEvent>WINDOW_NEWACTIVE which "Triggers when the foreground window changes". If the new windows you are trying to trigger on are not visible windows, you're out of luck... but if they are visible, then when they open, it will cause the "active foreground window" to change and this event will get triggered. At that point, if you want to determine if you indeed have a new window open now, you'd have to:
get a list of all currently open windows by:
- window title (no so good, how do you handle multiple windows with the same title)
- window handle (better, each is unique)
- process id (also unique)
For more on this, check out the following post in which I wrote something to track the opening and closing of multiple Notepad windows... perhaps you can use a similar approach.
http://www.mjtnet.com/forum/viewtopic.php?t=5350
Take care
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -