Jump to content
Macro Express Forums

Execute Once When A Window Opens


Recommended Posts

I need Mx to execute a few commands each time I add a record in my case management program. There are 12 types of records and one or more might be opened at one time.


I thought Mx could monitor the program, waiting until, for example, window "A" opens. Then it should execute a set of commands one time. Then it should just ignore the window (whether minimized, maximized, closed, etc.) until another window "A" is opened, and then do it again.


I came up with this solution. Problem is that it uses one variable for each menu plus one universal variable for a total of 13 variables.


Can anyone see a better way to do this?????


Repeat Until %T98% = "abcdefghijklmnopqrstuvwxyz"

--Wait For Window Title: "Event Form - Add"

--Keystroke Speed: 100 Milliseconds

--Text Type: <ALTD><ALTD>e<ALTU><ALTU>a

--Delay 2 Seconds

--Repeat Until %T99% = "N"

----Delay 2 Seconds

----If Window Title "Event Form - Add" is running

------Variable Set String %T99% "Y"


------Variable Set String %T99% "N"

----End If

--Repeat End

Repeat End


Thanks so much for any guidance you can give.

Link to comment
Share on other sites

One of the automatic activation features built in to Macro Express is Window Title. It is located in the Activation Pane of the Properties Tab. Whenever the window title of your choice gains focus, the macro will fire.


Remember, it is when a window gains focus. For example, clicking back and forth between the target window and your desktop 3 times will fire the macro 3 times.

Link to comment
Share on other sites



Thanks so much for the input. The Window Title automatic activation looked like the answer, except, as you imply, there's no stopping it!


When I tell my case management program ("TimeMatters") to allow me to add a record, it displays the "Event Form - Add" window, the macro fires and "types" the necessary command to cause the list of available "Auto Entry Forms" to display.


The thing is that I don't want the macro to fire again for this particular record. I don't want it to fire again when the option window disappears, or when the "Event Form - Add" record is minimized and later maximized, or when the "Event Form - Add" record is saved and reopened for editing. I only want the macro to fire once per record.


However, as soon as I click on an option, the option window closes, Mx "sees" the "Add Record" window title, and it fires the macro again, and again, and again.....


I might be able to add some steps and have the macro grab and save the record's unique ID. That way it could start by always checking to see if it has previously seen that record, in which case, it would abort. 'Problem is that it will take time and it will stilll burn up cycles constantly Activating, testing, and activating again.


Is there any way to make this Activation thing work once and only once for each record?


Thanks in advance for any help you can give.



Link to comment
Share on other sites

Is there any way to make this Activation thing work once and only once for each record?
No direct way that I can think of. I agree that you would need to trap the record number, save it a simple text file, to the Registry, or as an environment variable, and then wrap the macro in an If/End If construct. The macro would fire, but would not process. You may be surprised as to how fast all this can happen.


This is only a suggestion, there are probably other creative ways to solve the problem.

Link to comment
Share on other sites

Thanks again, Floyd.


I'll try the If/Then.


If its not feasible to pull the record number, then until/unless there is an option to Activate Once on Open, which also ignores the window when it is restored or maximized from a minimized state, I'll use a macro to (1) issue the "Add Record" command, and (2) then issue the command to display the AutoEntry forms, and (3) then stop. That way monitoring won't be an issue.


Jeffrey R. Mazor

Link to comment
Share on other sites

By the way, this doesn't solve the problem at all, but I see that saving & reopening is not an issue since upon reopening the record, the window title says something different like "Event Form - Change".


However, the problems remain: (1) constant activation while the initial Add record window is open, and (2) more constant activation when the window is restored or maximized from a minimized state.





Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...