Question about clipboard copy

When I use this action to copy clipboard and there is nothing in the field the macro cancels?

Is this the normal or is there something I can do to actually copy nothing?

Roger

The copy clipboard action does not fail for me when the clipboard is empty, as you can see below (the Beep occurs.) So perhaps you should show your macro.

I also tried the copy system clipboard to Clipboard Repository and it had the same results. If the field I am copying has something in it it works but if it is blank the macro cancels.

Now that you've shown me your macro, I can investigate. Prior to showing me your code, I was assuming your code was different. It always helps to show your code.

Okay, I think I found the problem and the workaround.

The problem appears to be that the Copy action causes a timeout of 10 seconds. These are the setting which you can see for yourself if you click on the cogwheel for the Copy action.

You can change those settings to not abort, but then you have to ask yourself another question... what do you want to happen if there's nothing in the clipboard? If you don't answer this question, and handle the consequences, then your macro may do the wrong thing. Tell me what you want to do and I can help you fix your code.

But your discovery is noteworthy and interesting. I was not aware of this behaviour or these timeout values. Thanks for helping me learn.

I want it to just do nothing if there is nothing in the clipboard just copy nothing to the clipboard repository.

I did not know there was a timeout either. I set the time out to 1 second and unchecked both options. I also checked the timeout aborts the micro. But that did not help.

Thanks

Screen Shot 2022-03-10 at 4.44.06 PM

Hmmm, I don't think you understand the idea of timeouts. A timeout stops the action and then continues with the following action. Now that you answered my question, which was "what do you want to do if there's nothing in the clipboard" which you answered with "I want to do nothing" then we can fix that. I offered to write the code if you answered the first question, and now that you've answered that question I can write the correct code. Here's what you need after the Copy action.

Without that image, upper macro will NOT do NOTHING, but will continue with all your following actions. But now that you've told me what you want, which is nothing, I was able to give you the correct fix. (There are other ways to fix it, but that's one way.)

Also, I need to ask why you wrote "that did not help." It may not have fixed your complete problem but it certainly did help because it would have solved the first problem which was the timeout. You aren't getting the timeout anymore, right? So that's a change in behaviour. Now we deal with the second problem. I couldn't fix both at the same time because I didn't know what you wanted to do after fixing the first problem. Separate problems require separate solutions.

Try checking if the Edit->Copy menu item is enabled or not, before doing the copy.

That's an excellent idea - detecting the problem in advance, rather than after the fact.

But I have to admit that it is surprising and confusing that the Copy action has a timeout. Why doesn't it just return nothing immediately?

From the Keyboard Maestro wiki on the Copy,Cut, Paste Actions:

They operate primarily by simulating the appropriate command key (Command-X, Command-C, Command-V) with small pauses to allow the application to process the clipboard. The Cut and Copy actions wait until the clipboard changes before proceeding.

It is possible the "wait until clipboard changes" is giving you issues if nothing is copied. So, the copy Action in your Macro could be replaced with this Action which does the same thing without any pauses or waiting:

Thanks to all for help and suggestions.

I now have it working. I guess I need to read the documentation closer as I missed the fact that Cut, Copy, and Paste actions have built in pauses. I had many pauses in my macro. When I removed the pauses and changed the timeout and abort on the Copy action it started to work.

Again thanks for helping my 83 year old brain see the light.

Roger

2 Likes

Thanks. That's inspiring. I hope I'm still using KM at your age.