Jump to content
Macro Express Forums
Shikabane Hime

Running in specific windows/processes

Recommended Posts

Here's the basic situation:

 

I want the macro to run on a specific window or process that is running the background while being able to browse the web or whatnot.

 

For example if I had notepad open and I wanted it to type the letter "b" a thousand times every 5 seconds for some odd reason, but I wanted to read the news without getting another computer, I can move away from notepad and surf the web while the macro continues to type b in the text editor.

 

I would first set the specific process scope to "notepad.exe", but not sure what to do afterwards. I've tried if the program is running cause the help file says the program can be running in the background, but that didn't work.

 

Question:

 

How to run the macro in specific windows or processes in the background without affecting any other applications?

Share this post


Link to post
Share on other sites

Normally, no. Windows only accepts keystrokes and mouse events (clicks & moves) for the window that has focus. However, you may have success if you use the Window Control commands and avoid certain macro commands that only work with the foreground window.

 

For a sample macro that demonstrates this, open the samples.mex file (installed with Macro Express) and look at the macro titled 'Calc ulator and Note pad' (the extra spaces are part of the name).

Share this post


Link to post
Share on other sites

Of course, the very specific thing you mentioned can be done, though it's certainly not what you actually intend to do.

 

Repeat Until %T1% <> %T1%
 Repeat Start (Repeat 1000 times)
Variable Set String %T1% "b"
Variable Modify String: Append %T1% to Text File
 Repeat End
 Delay 5 Seconds
Repeat End

 

<REP3:08:000002:000001:0001:1:01:T1><REP3:01:000001:000001:01000:0:01:><TVAR2:01:01:b><TMVAR2:20:01:00:000:000:C:\Users\Steven\Documents\Macros\Macro Test Files\appendtext001.txtF><ENDREP><DELAY:5><ENDREP>

This will cause Macro Express to add the letter b to a text file 1000 times, then wait 5 seconds before doing it again. It's set to run

forever (or until canceled). While it is doing this, you can use your computer as you wish, but you won't be able to use any other

macros.

 

As far as I can figure, it is a completely pointless macro. I understand your example was simply to give an idea of what you want

to do, but I hope that my response to your example can help you figure out a work-around for what it is you want to do (or help

you come up with an idea of something similar but different, that you can figure out or we can help you figure out how to do).

Share this post


Link to post
Share on other sites

I see..my example wasn't the greatest and was pretty general.

Then here's another one:

 

Suppose I want to open the help menu for some generic application using the F1 shortcut, but I want it to open up when the app is unfocused.

Sending <F1> to the control ME doesn't seem to work in this case.

 

When I tried it on notepad, it types <F1> instead.

 

This example is closer to what I want, but I guess this is also one of the cases where the window itself must be on top in order to run.

Share this post


Link to post
Share on other sites
Suppose I want to open the help menu for some generic application using the F1 shortcut, but I want it to open up when the app is unfocused.

Sending <F1> to the control ME doesn't seem to work in this case.

 

When I tried it on notepad, it types <F1> instead.

 

This should not be too hard to do -- provided you allow the non-focused window to momentarily get focus. This is not perfect, but hopefully will get you started:

 


<REM2:T1 = Window that currently has focus...>
<TVAR2:01:06:><REM2:Bring Notepad to the foreground, or launch it if it is not running...>
<LAUNCHYES3:0:0112- Notepad
<LAUNCH:C:\Windows\System32\notepad.exe>
<REM2:Wait up to five seconds for Notepad to get focus (but it should not take nearly that long)>
<WAITWIN2:000000:000005:Notepad>
<TEXTTYPE:<F1>>
<REM2:Wait up to five seconds for Help to get focus (but it should not take nearly that long)>
<WAITWIN2:000000:000005:Help>
<REM2:Switch back to original window...>
<ACTIVATE2:%T1%>

 

 

In ME pseudo code:

Variable Set String T1 from Window Title

Active or Launch Notepad

Wait for Window Title Notepad

Text Type <F1>

Wait for Window Title Help

Activate Window T1

Share this post


Link to post
Share on other sites
I want to open the help menu for some generic application using the F1 shortcut, but I want it to open up when the app is unfocused.

Sending <F1> to the control ME doesn't seem to work in this case.

 

When I tried it on notepad, it types <F1> instead.

 

This example is closer to what I want, but I guess this is also one of the cases where the window itself must be on top in order to run.

Here's the rough work-around I put together. I also thought about having the window momentarily gain focus, which would be mildly

annoying, but sometimes you do what you have to do... but then I thought about hiding the window before activating it. I tested it

on Notepad and also on Internet Explorer, and it seems to work. The only problem is deciding at what point to unhide the window.

 

Here is my little test macro:

Window Hide: "Windows Internet Explorer"
Activate Window: "Windows Internet Explorer"
Text Type: <F1>

<WHIDE:Windows Internet Explorer><ACTIVATE2:Windows Internet Explorer><TEXTTYPE:<F1>>

If I were going to just have the window activate, then go away, I would probably do something like this (depending on how fast your

system is, this could go very quickly... on my computer (Vista 32, 4GB RAM, Intel Quad 2.6 GH, it screams, I hardly notice the window

activating; whereas my work computer is XP Prof, 512 RAM, P3 or low-end P4, I can imagine it taking as long as a whole second

depending on how many other processes are running):

Activate Window: "Windows Internet Explorer"
Wait For Window Title: "Windows Internet Explorer"
Text Type: <F1>
Window Minimize: "Windows Internet Explorer"

<ACTIVATE2:Windows Internet Explorer><WAITWIN2:000010:000000:Windows Internet Explorer><TEXTTYPE:<F1>><WMIN:Windows Internet Explorer>

Share this post


Link to post
Share on other sites

Ha Ha!!!

 

So I just tried another little experiment that worked surprisingly well. Still don't know if this will work 100% for what you need,

but it is definitely something to check out, IMHO.

 

It has to do with hiding the window. This worked perfectly. (I have the hidden window re-appear at the end of the macro, for

simplicity, but I didn't originally... the text type happens while the window is still hidden.)

 

Window Hide: "Untitled - Notepad"
Activate Window: "Untitled - Notepad"
Text Type: Macro Express Rules
Window Show: "Untitled - Notepad"

<WHIDE:Untitled - Notepad><ACTIVATE2:Untitled - Notepad><TEXTTYPE:Macro Express Rules><WSHOW:Untitled - Notepad>

 

Now, depending on how much you have going on in the "hidden" window, if you end up clicking a different window, you may

change the focus, screwing up your macro... but that will take a bit more experimenting.

Share this post


Link to post
Share on other sites

Clever idea, Steve. Could be very be useful in situations when you merely want to read or or browse in another application window. From the following superficial test, any manual activity in that or any other window causes malfunction.

 

I opened a folder of images in a maximised window, with the intention of browsing them. Then I tested the following macro a couple of times.

 

<REM2:Testing whether an ME macro can in effect run in the background, using Steve's neat method><WHIDE:Untitled - Notepad><REP3:01:000001:000001:00010:1:01:><ACTIVATE2:Untitled - Notepad><TEXTTYPE:%N1% This is testing whether an ME macro can in effect run in the background, using Steve's neat method.<ENTER>><ENDREP><WSHOW:Untitled - Notepad><MRETURN>

 

During run #1, I did nothing but look at the screen

Result: No problems. (Took about 24 seconds, about 1s more than simply using the Repeat loop directly on a permanently visible Notepad window.) This is what I saw in Notepad when it reappeared:

 

1 This is testing whether an ME macro can in effect run in the background, using Steve's neat method.

2 This is testing whether an ME macro can in effect run in the background, using Steve's neat method.

3 This is testing whether an ME macro can in effect run in the background, using Steve's neat method.

4 This is testing whether an ME macro can in effect run in the background, using Steve's neat method.

5 This is testing whether an ME macro can in effect run in the background, using Steve's neat method.

6 This is testing whether an ME macro can in effect run in the background, using Steve's neat method.

7 This is testing whether an ME macro can in effect run in the background, using Steve's neat method.

8 This is testing whether an ME macro can in effect run in the background, using Steve's neat method.

9 This is testing whether an ME macro can in effect run in the background, using Steve's neat method.

10 This is testing whether an ME macro can in effect run in the background, using Steve's neat method.

 

---------

 

During run #2, I scrolled down the screen a few times, to see more images.

Result: That was interrupted in various odd ways, with no activity by me. For example, an image opened in my default JPG viewer, IrfanView. This is what I saw in Notepad when it reappeared:

 

1 This is testing whether an ME macro can in effect run in the background, using Steve's neat metho2 This is testing whether an ME macro can in effect run in the3 This is testing whether an ME macro can in effect run in the background, using4 This is testing whether an ME macro can in effect5 This is testing whether an ME macro can in effect run in the ba6 This is testing whether an ME macro can in effect 8 This is testing whether an ME macro can in effect run in the background, using Steve's neat method.

9 This is testing whether an ME macro can in effect run in the background, using Steve's neat method.

10 This is testing whether an ME macro can in effect run in the background, using Steve's neat method.

 

--

Terry, East Grinstead, UK

Share this post


Link to post
Share on other sites

I like the hiding window idea. Very creative.

But I accidentally aborted the macro in between, and now the window is hidden.

 

Is there a way to bring it back without restarting?

Also, what if I wanted to unhide the window if I decided to abort? Not really sure if abort is simply stop running on the spot, or if there's anything in between I can do.

Share this post


Link to post
Share on other sites

Hey Terry,

 

Yeah, I had a similar problem.

 

I stuck with the "Macro Express Rules" text and had it type 100 times on the hidden notepad, then I periodically clicked on an open

word processor page (I used OpenOffice.org Writer, but I don't think it would make a bit of difference if I used Word or Word Perfect),

and the macro continued running, it just happened to finish typing the 100 "Macro Express Rules" into the .odf document.

 

So I modified the macro to have an "If/Else" clause. Essentially:

 

If notepad active
 Text type ME Rules
Else
 Activate notepade
 Text type me rules
End if

 

This worked better, but whenever I clicked into the .odf document there was a chance that the macro would already be within the "If/Else"

clause. Sometimes it worked, but mostly it messed up a little, then went back to the notepad to continue. For most practical applications

that I can think of, if you mess up a little bit, you've pretty much messed up the whole thing.

 

However, it could be useful under certain circumstances... just none that I can think of specifically (beyond reading a blog, news page, etc.

where you don't need to be clicking till after the macro has finished running).

 

Still, I love playing with macros, so experimenting with this task has been enjoyable.

 

PS - I've noticed something in the past, but haven't thought twice about it till now. When using Clipboard to paste in Text Type, it is

considerably slower than having the text typed out normally. The above macro ran in about 5 seconds (give or take) when

typed normally, but took as long as a minute when using the clipboard function.

 

Is that because when using the clipboard function in the Text Type command, it is actually using a Ctrl+C type process, including all the

pre-set delays within Macro Express? I had always assumed that using this function would be faster than typing normally (and I imagine

it is faster when dealing with extaordinarily long bits of text), since I thought ME just took the information and pasted it in it's own right.

But it is obviously much much slower, leading me to suspect it is using the outside clipboard to save/paste.

 

Would manually reducing the delays increase the speed of text-type processes using the clipboard? Not that I necessarily would...

clipboard commands need those delays, in my opinion (my work PC sucks), I'm just curious.

Share this post


Link to post
Share on other sites
I like the hiding window idea. Very creative.

But I accidentally aborted the macro in between, and now the window is hidden.

 

Is there a way to bring it back without restarting?

Also, what if I wanted to unhide the window if I decided to abort? Not really sure if abort is simply stop running on the spot, or if there's anything in between I can do.

 

Yes, this can be a little bit of a problem.

 

What I would do is create a second macro that is nothing more than:

 

Window Show: "specific window"

 

That way if your window gets stuck hidden, you can un-hide it pretty easily.

 

What I was doing with mine, was actually just changing the Hide command to a Show command, and then running the macro again.

 

Either way will work.

Share this post


Link to post
Share on other sites

Steve,

 

I can't answer your question about the significant difference in text processing speed, but I'm sure one of the ME support guys will be able to do so. I haven't used the clipboard method yet, but will experiment some time soon.

 

BTW, your processing seems much faster than mine. If I've understood you correctly your macro typed 100 lines of "Macro Express Rules", total 1,800 characters. Mine took 24 secs to type 10 lines of 99 (including the variable), just under 1,000 chars. Yours was 5 times faster for about twice the work - a factor of nearly 10 to 1!

 

Could you run my macro as it stands and tell me how long it takes please? This PC is Intel CoreT 2 Quad Core Q9450 (2.66 GHz, 12 MB cache, 1333 MHz); 4 GB DDR2 667 MHz Memory (although, using XP Pro, not all of it gets utilised).

 

--

Terry, East Grinstead, UK

Share this post


Link to post
Share on other sites
Steve,

 

I can't answer your question about the significant difference in text processing speed, but I'm sure one of the ME support guys will be able to do so. I haven't used the clipboard method yet, but will experiment some time soon.

 

BTW, your processing seems much faster than mine. If I've understood you correctly your macro typed 100 lines of "Macro Express Rules", total 1,800 characters. Mine took 24 secs to type 10 lines of 99 (including the variable), just under 1,000 chars. Yours was 5 times faster for about twice the work - a factor of nearly 10 to 1!

 

Could you run my macro as it stands and tell me how long it takes please? This PC is Intel CoreT 2 Quad Core Q9450 (2.66 GHz, 12 MB cache, 1333 MHz); 4 GB DDR2 667 MHz Memory (although, using XP Pro, not all of it gets utilised).

 

--

Terry, East Grinstead, UK

Terry,

 

I'm at work now (work PC is a joke), but I'll be happy to try it as soon as I get home (couple hours). It looks like our systems are pretty

close to identical (I'm running Vista Ultimate 32 bit is the only obvious difference I see). I was estimating the time it was taking to run the

macro. Typing it "normally" was screaming fast, though. And using the paste function was so unbearably slow that I actually thought the

macro had hung up on something, till I ran it on a visible notepad (so I could see that it really was doing the job, just slowly).

 

Anyway, I'll actually time it and let you know what I find out once home.

Share this post


Link to post
Share on other sites
Terry,

 

I'm at work now (work PC is a joke), but I'll be happy to try it as soon as I get home (couple hours). It looks like our systems are pretty

close to identical (I'm running Vista Ultimate 32 bit is the only obvious difference I see). I was estimating the time it was taking to run the

macro. Typing it "normally" was screaming fast, though. And using the paste function was so unbearably slow that I actually thought the

macro had hung up on something, till I ran it on a visible notepad (so I could see that it really was doing the job, just slowly).

 

Anyway, I'll actually time it and let you know what I find out once home.

Ok Terry,

 

I just ran your code on my machine at home, and it completed in 4:26 seconds.

 

Interestingly enough, when I ran my code ("Macro Express Rules" 100 times), it completed in 3:84 seconds.

 

Obviously there will be some discrepancy based on my own reaction times, but both instances are pretty dern fast.

 

When I switch to using the clipboard to paste, my 100 repeats took just over 52 seconds.

 

Yours, set to paste, took just over 8 seconds.

 

It's strange that your computer takes so much longer than mine, when our specs are virtually identical. Unless Vista really is that

much better than XP...

Share this post


Link to post
Share on other sites

Alright, I have it working the way it should based on the hidden window idea.

 

Except now I want to have two windows with the same name.

 

How does the program scope work? Both processes have the same names, but I didn't think the macro would run on BOTH processes even though only one was selected.

Share this post


Link to post
Share on other sites

Thanks Steve, appreciate your taking the time to test it.

 

OK, after some further work, I reckon I've found the reason for this major difference. I'm guessing that if you look at Options > Preferences < Delays you'll find your setting is 300 microseconds. That's the default. At some time, for reasons I can't recall, but which were probably concerned with getting more stable operation of some text-typing macros, I must have changed mine to 10,000 microseconds (10 ms).

 

Trying my macro again with various different settings, I get the following results:

 

300 µS: 4.2 seconds

1,000 µS: 5.2 seconds

10,000 µS: 24 seconds

 

For the time being, I've set it back to the compromise setting of 1,000 µS (1 ms).

 

--

Terry, East Grinstead, UK

Share this post


Link to post
Share on other sites
Alright, I have it working the way it should based on the hidden window idea.

 

Except now I want to have two windows with the same name.

 

How does the program scope work? Both processes have the same names, but I didn't think the macro would run on BOTH processes even though only one was selected.

I just tested it and it looks like when you have two windows open with identical names, it will go with which ever one was the one most

recently "Active."

 

I opened two notepads, then ran the macro. The window that took the "Hide" command was the second notepad. The first one just sat

there. So the window that got hidden still took precedence when the macro activated notepad, and so the hidden window took the text

as well.

 

I tried having two separate "Hide" commands, so that both notepads would be hidden, and that worked fine. Only one of the notepads

took the text (the first one opened, this time, since it became the "Active" window when it was hidden - the second notepad opened

being the first to be hidden). At the end of the macro I set two "Show" commands, but only the notepad that had taken the text

reappeared. In fact, I couldn't get the blank notepad to reappear until I closed the one that was visible. So that's kind of a problem.

Not sure how to work that out without some obnoxious work-around command-builds.

Share this post


Link to post
Share on other sites

My temporary solution is to simply ignore the any additional instances of the program and focus on a specific window (by bringing up the window I want). This way, it will show and hide that window until I accidentally bring up the other window, which then just means I'll have to restart the app.

 

Although another minor issue would be how in order to perform the macro on the specific window, I lose focus on say my web-browser and I have to click it again just to resume work.

 

But I guess that can't be helped, since it only detects keystrokes on the window it's currently focused on.

Share this post


Link to post
Share on other sites
Thanks Steve, appreciate your taking the time to test it.

 

OK, after some further work, I reckon I've found the reason for this major difference. I'm guessing that if you look at Options > Preferences < Delays you'll find your setting is 300 microseconds. That's the default. At some time, for reasons I can't recall, but which were probably concerned with getting more stable operation of some text-typing macros, I must have changed mine to 10,000 microseconds (10 ms).

 

Trying my macro again with various different settings, I get the following results:

 

300 µS: 4.2 seconds

1,000 µS: 5.2 seconds

10,000 µS: 24 seconds

 

For the time being, I've set it back to the compromise setting of 1,000 µS (1 ms).

 

--

Terry, East Grinstead, UK

 

Steve: To close off this one, can you advise what your setting is please?

 

--

Terry, East Grinstead, UK

Share this post


Link to post
Share on other sites
Steve: To close off this one, can you advise what your setting is please?

 

--

Terry, East Grinstead, UK

Oh, yeah, sorry:

 

Delay after clipboard commands: 250

Text Type delay: 300 microseconds

Use High Speed Timer: checked

Share this post


Link to post
Share on other sites
Although another minor issue would be how in order to perform the macro on the specific window, I lose focus on say my web-browser and I have to click it again just to resume work. But I guess that can't be helped, since it only detects keystrokes on the window it's currently focused on.

You could do this:

If Not Window Title "All Products - Windows Internet Explorer" on top
 Activate Window: "All Products - Windows Internet Explorer"
End If
Text Type: Type text in browser window ...

Of course you need to change the window title to match the one you use.

Share this post


Link to post
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.

Guest
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.

Loading...

×
×
  • Create New...