Macro keeps giving a system warning beep

I have this macro that opens a pages file, then copies it to the clipboard. Later on it is pasted into a numbers spreadsheet. That part works flawless.

The part below works fine! But, almost always, there is a system warning beep. I tried to figure in what step that beep is triggered by running it step by step, varying the pauzes etc. But nothing was found that way. The problem is that it does not always happen. Although that is rare. How do I find what triggers it?

the problem script Macro (v11.0.3)

the problem script.kmmacros (5.7 KB)

1 Like

It's possible that a keystroke is sometimes sent too early for the application, which could result in an alert sound — this would also explain why you can't replicate it debugging action by action.

You could try using Pause until after activating Pages with the condition that it's the front application. You could also try lengthening the pauses between all the actions, which you could make easier on yourself using Set Action Delay.

1 Like

An even better way than using pauses is to modify your macro to actually check if the application is ready for the keystroke (instead of using Pause actions.) Usually you can do this with an action like this:

image

In fact, there is much more than could possibly be done to simplify this macro. Consider this:

I didn't thoroughly test it, but it seemed to run without error and do something, so maybe it will solve your needs.

1 Like

Thanks for the suggestions, I'll try them tomorrow and report back!

1 Like

Yes, my guess if you are getting a beep noise would be a timing issue where one of the actions that simulates a keystroke (including the Copy which simulated Command-C) is happening before the application is ready for it (or alternatively, is a key that the application is never ready).

If the beep happens reliably with the macro as it, try adding a large pause (say 5 seconds) somewhere in the middle of the macro and see if the beep happens before or after that (or not at all). Then move the Pause action forward or backwards in the macro. Presumably, if the beep happens reliably, then if the Pause is right at the start of the macro the beep would always happen after it, so move it further in to the macro until either the beep stops (because a pause is needed at that location) or the beep is before the pause, so you know where the cause is.

1 Like

Found the problem using the long delay. The fact that the macro worked fine, despite the beep, made me think it was a repeat command that was the issue. It turnes out that the pages file opens with all the text already selected most of the time. In that case the cmd-A is not necessary and generates the beep. I added a mouse click in the center to ensure no text is selected before the cmd-A. That solved the problem😃.
But it took me some time to figure out why all the text is selected when opening a file. It turnes out that Pages remembers that all the text in a file was selected the last time, before the cmd-W is given. So when you reopen that file, all the text is still selected. Since, for testing, I was frequently using the same files, that was the case.

2 Likes

You did a very good diagnosis there. That's new to me too.

The alternate solution I offered could also be made to work in your situation by either:

  1. Creating a timeout on the Pause Until action, and also turning off the failure flags on the final action; or,
  2. Group the final two actions in a Try action.

Thanks, I'll try your approach on a test macro just to learn how it works, because I have not quite figured out the mechanics of that one. But glad to try out new things and learn more about KM that way!

1 Like

This works, but I had to add the mouse click before the "for each" action to ensure no text was selected already! Otherwise the same problem occurred, where in this case the macro stopped until a mouse click in the pages window.

Thank you again, I implemented this and it speeds things up considerably !

That's odd. Yes, I see an inconsistency in how Pages work with regards to the enabling of the Select All menu item. I.e., it doesn't seem to realize sometimes that all the text has already been selected, so the menu item is enabled even when all the text is already selected. It seems like a small bug in Pages, but I'm glad you found a workaround.

1 Like