Triggers for Window Open/Close

Ideas for new features & functions

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Triggers for Window Open/Close

Post by Bob Hansen » Wed Mar 04, 2009 4:40 pm

I have started a new subject as a follow up to an earlier posting here: http://www.mjtnet.com/forum/viewtopic.php?t=5350

jpuziano wanted to count how many times Notepad was opened and closed.
He found that the OnEvent triggers normally fire all the time a Window is open, but wanted a trigger that fired when the Window was actually opened and was actually closed. This triggered a number of discussions.

I made the suggestion to make a small script to update an INI file and have that macro triggered by the Macro Scheduler built in Trigger Events. That explanation by me was not clear, so I made the time to do it myself. Here are two scripts to do the work:

CountProgramOpenings.scp

Code: Select all

/*
Purpose:
To count the number of times a program is opened.
Triggered in Macro Scheduler Event: WindowOpen, enter name of window

Designed with 
    XP-PRO SP2
    Macro Scheduler 11.1.05 

Tested with "Calculator"
=============================================================
*/

// Open Program counter
IfFileExists>ProgramCounter.ini,UpdateINI
WriteLn>ProgramCounter.ini,vResult,[Counters]
EditIniFile>ProgramCounter.ini,Counters,Opened,0
EditIniFile>ProgramCounter.ini,Counters,Closed,0

// Get INI Opened/Closed/Active values
Label>UpdateINI
ReadIniFile>ProgramCounter.ini,Counters,Closed,vClosed
ReadIniFile>ProgramCounter.ini,Counters,Opened,vOpened
Let>vActive=%VOpened%-%vClosed%

// Update current counts
Let>vOpened=%VOpened%+1
Let>vActive=%vActive%+1

// Write new INI Opened value
EditIniFile>ProgramCounter.ini,Counters,Opened,%VOpened%

MessageModal>Active copies of Program: %vActive%
CountProgramClosings.scp

Code: Select all

/*
Purpose:
To count the number of times a program is closed.
Triggered in Macro Scheduler Event: WindowClose, enter name of window

Designed with 
    XP-PRO SP2
    Macro Scheduler 11.1.05 

Tested with "Calculator"
=============================================================
*/

// Closed Program counter
IfFileExists>ProgramCounter.ini,UpdateINI
WriteLn>ProgramCounter.ini,vResult,[Counters]
EditIniFile>ProgramCounter.ini,Counters,Opened,0
EditIniFile>ProgramCounter.ini,Counters,Closed,0

Label>UpdateINI
// Get INI Opened/Closed/Active values
ReadIniFile>ProgramCounter.ini,Counters,Closed,vClosed
ReadIniFile>ProgramCounter.ini,Counters,Opened,vOpened
Let>vActive=%VOpened%-%vClosed%

// Update current counts
Let>vClosed=%VClosed%+1
Let>vActive=%vActive%-1

// Write new INI Closed value
EditIniFile>ProgramCounter.ini,Counters,Closed,%VClosed%

MessageModal>Active copies of Program: %vActive%
Using Macro Scheduler trigger tools, I set CountProgramOpenings.scp to trigger On Event/Window Open and I set CountProgramClosings.scp to trigger On Event/Window Closed. Thought I was done.

Then, to my surprise, I found that they trigger just like the commands for OnEvent, they did not fire each time a new window opened up or closed. They keep running once they start and do not fire again.

I never thought to test for multiple windows in the past, and always thought that when the defined window opened, the macro script would trigger. This is an unpleasant surprise. I could accept how the script commands worked, but did not expect a similar behaviour with the scheduling tools.

I would like to see two enhancements:
1. Allow the scheduler tools to trigger the scripts every time the defined window is opened/closed, allowing multiple windows to fire each time.
2. Provide the script commands with event triggers for when the windows actually open/close, in addition to the existing ones that run while they are open/closed.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Re: Triggers for Window Open/Close

Post by jpuziano » Wed Mar 04, 2009 5:30 pm

Bob Hansen wrote:I would like to see two enhancements:
1. Allow the scheduler tools to trigger the scripts every time the defined window is opened/closed, allowing multiple windows to fire each time.
2. Provide the script commands with event triggers for when the windows actually open/close, in addition to the existing ones that run while they are open/closed.
Way to go Bob, great work. I heartily second this request... particularly part 2. :D
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 - :-)

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts