Jump to content
Macro Express Forums

Macro continue after file is saved.


Recommended Posts

Macro continue's before file is saved.

 

Problem is files are created using a counter:

File: Bob 001

File: Bob 002

File: Bob 003

There for "Wait for File to Exist" does not seem to be a solution.

 

Hundreds of files are involved.

 

This is MacroExpress Pro 4.2.2.1 code:

Window Activate: Robert's Help

Mouse Move: 628, 1032 Relative to Screen

Mouse Left Click

Text Type (Simulate Keystrokes): <CONTROL><SHIFT>r

 

The program I'm using "SnagIt 10" is called by the "<CONTROL><SHIFT>r"

 

Bob

Link to comment
Share on other sites

If you don’t want to reply on outside help from another app or macro then you need to write a routine that scans the folder periodically until a change is detected. A simple way to do this is to count the number of files before executing SnagIt. Then after the command is executed create a loop that would last slightly more than the maximum length of time required. Suppose at most SnagIt takes 5 seconds. I would then create a loop of 50 iterations with 100mS delays. IE 10 times a second. Now in that loop count the number of files. When the count no longer matches Break out of the loop and continue. Super simple. Beware that you might need to add some timing because files can exist and yet not be ready. IE it takes an amount of time for the app to write to the file.

 

If you need to know which file changed there’s another approach. Instead of counting use an accumulator variable. Before executing SnagIt repeat with folder and append text of the file name to a variable. Let’s call it Cache. Now do like before checking every 100mS or whatever but this time the logical comparison is “If %Cache% does not contain %File%” If this tests true Break and %File% is your new file. Now you can do a “Wait for File Ready %File%”. This is the preferred method IMHO.

 

I didn’t mention it to keep things simple but you should always delimit caches like that. IE stick a character between them. I like the pipe colon “|” (Shift+Backslash). Modify my example above to initiate with a pipe and then append %File%|. It will look like |File1.txt|File2.txt| and so on. The reason being you could have a substring match. Say the file name being evaluated is 100.txt. If in the cache there’s already a file named 1100.txt then it will falsely match. But if delimited you will search for |100.txt| which cannot result in a match.

 

Another trick to do this is to create a helper macro which is activated by a change in folder contents. You can enable it when your macro starts in the macro and when it detects a change it could drop a trigger file someplace, even the same folder. Point being you will know its name in advance and can use Wait for File Exist. EG this helper can drop a file named trigger.txt in that folder or any other folder when folder mod activation trips it. Now in your macro delete trigger.txt and go about your business. There are many similar tricks like this with helper macros.

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.

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