The problem is that when nothing is selected the first Copy action will fail either aborting the Macro or, (if set not to Abort) leaving the Clipboard with whatever was in it before the Macro was run.
I've modified your Macro to the below, adding a test to see if the menu item Copy is enabled.
On testing I found that the calculation test CHARACTERS (%SystemClipboard%) made no difference. I think it is there to test whether the clipboard contains text or something else, like an image? The problem is that even it the clipboard contains an image it returns a count of "1" which means it is the same if you selected a single letter. So, assuming you are using this just for text, your macro can be further simplified to:
The key to making this work is the CLIPBOARDSEED() function. This function simply returns a unique integer whenever the clipboard changes. Here's the fairly simple macro built using that function:
Macros are always disabled when imported into the Keyboard Maestro Editor.
The user must ensure the macro is enabled.
The user must also ensure the macro's parent macro-group is enabled.
System information
macOS 14.4.1
Keyboard Maestro v11.0.2
The macro first records the current clipboard seed, tries the copy command, then checks to see if the clipboard seed value changed. If it did, something was copied; if it didn't, nothing was copied, i.e. there wasn't anything selected.
If nothing was copied, the macro inserts a quote. If something was copied, the macro first makes sure it was text, and if so, wraps the copied text in quotes.
The only tricky bit is actually in the Copy command: If you try to run Copy and no Copy item exists (i.e. the menu item isn't active), the Copy command will, by default, keep trying to run until it times out. If you click the gear icon for the Copy command in this macro, you'll see that both Timeout Aborts Macro and Notify on Timeout are disabled. Further, and more important, Set Action Timeout is set to only five hundredths of a second:
This is to make the macro run much faster—if it tries Copy and it fails, it gives up after only five hundredths of a second. You may need to increase this number depending on the speed of your Mac and the app in question. You want to make it as low as possible, but high enough such that when you run the macro with text selected, it works.
By using a low timeout value and disabling the default abort/notify actions, the macro continues on very quickly when you don't have anything selected.
I've tested this in TextEdit and it seems to work perfectly.