Jump to content
Macro Express Forums

Handling OS messages when saving files


Recommended Posts

When running macros that save files they frequently fail because messages from the OS do not automatically pause the macro to allow user interaction before proceeding. A typical example:

 

  // Now re-open the file in F2 mode and enter the new name
  Text Type (Simulate Keystrokes): <F2>
  Delay: 0.1 seconds
  Text Type (Simulate Keystrokes): %tFilename%
  Delay: 0.1 seconds
  Text Type (Simulate Keystrokes): <ENTER>
  Delay: 0.1 seconds
  Text Type (Simulate Keystrokes): <ARROW DOWN>
  Delay: 0.1 seconds
End Repeat

After the ENTER command I might briefly see a message like "A file of this name already exists..." and be asked to choose a Yes or No option (e.g. to save with a suffixed name), but the macro continues regardless. Sometimes the fix is easy; for example when the message is asking whether to overwrite the previous file I can often safely insert a Text Type Y command. Or I can use If Window, specify 'Replace File', and add an appropriate  action, such as a simple Pause. Or sometimes an If File Exists command is possible. But sometimes it's not so easy.

 

What techniques do others use please?

 

Terry, UK

Link to comment
Share on other sites

I don't understand why you don't use the MEP file manipulation commands. It's much easier to conditionally handle exceptions with them. Much faster and more reliable. Since this is the way I handle files, I am not going to be of much help, but I urge you to try and use them instead. 

When I things that could have a popup error I use the existence of the controls. Let's say that's a "Do you want to continue?" button. I define the control and use "if control exists". And I'd never type in file names, I'd use the controls to enter those values. And here again, checking of the controls exist are useful. What I'm saying is not only can you use the controls to do things, you can also use their existence and value to control the flow of your macro. 

Link to comment
Share on other sites

3 hours ago, Cory said:

I don't understand why you don't use the MEP file manipulation commands. It's much easier to conditionally handle exceptions with them. Much faster and more reliable. Since this is the way I handle files, I am not going to be of much help, but I urge you to try and use them instead. 

When I things that could have a popup error I use the existence of the controls. Let's say that's a "Do you want to continue?" button. I define the control and use "if control exists". And I'd never type in file names, I'd use the controls to enter those values. And here again, checking of the controls exist are useful. What I'm saying is not only can you use the controls to do things, you can also use their existence and value to control the flow of your macro. 

 

"I don't understand why you don't use the MEP file manipulation commands."

I'm not sure I've understood. Apart from If File Exists, which I mentioned, what other  'file manipulation commands' do you suggest to handle file saving when OS messages are displayed as in my example? Or maybe you're referring to the simple way I've handled  the file processing in that? IOW, are you instead recommending a Repeat with Folder to build a variable holding all files? If so, I agree, and if this was a larger project with many more files involved that's probably how I'd do it. But this was just a simplified example to focus on the subject issue.

 

"I'd never type in file names..."

Do you mean you don't use string variables to enter data as in my example? What advantage would using Controls offer? Wouldn't that involve more steps, and the same variable?

 

"When I things that could have a popup error I use the existence of the controls."

How would you do that for my example? What would be the target of the Get Control command, for instance?

 

 

 

 

Link to comment
Share on other sites

In a multi step script, when there is little (or no) or no choice but to check for the presence of particular windows, I use the strategy of using (and reusing) a Boolean variable to signal whether the script is proceeding according to plan:

 

// Section 1
// Wait for "Hello" window to appear
Variable Set Bool %IsSuccess% to "False"

If Window "Hello" is focused
  Variable Set Bool %IsSuccess% to "True"
End If
If Variable %IsSuccess% Equals "False"
  Text Box Display: Script problem - Section 1
  Macro Stop
End If

// "Hello" window has appeared, perform next action... 

// Section 2
Variable Set Bool %IsSuccess% to "False"

...

If Variable %IsSuccess% Equals "False"
  Text Box Display: Script problem - Section 2
  Macro Stop
End If

 

I find this approach very helpful when debugging scripts that are inherently unreliable due to their complexity.

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

×
×
  • Create New...