Prompt with empty text field not working reliably on macOS

I have created an action with a prompt including a text field.

This action does always work on my iOS and iPadOS devices and it does always work on macOS when the text field is not empty.

But when the text field is empty it does work on macOS only every now and then. That’s the only way I can describe it, I could not detect any pattern. If it didn’t work at all I’d assume there is a mistake in my code. But it does work—occasionally.

And no, it does not not work just with certain buttons. And yes, I have a condition in the script handling the prompt data that does not process prompt_text when it is does not have content.

Can you share the action so others can reproduce the issue and see if a pattern can be identified?

Of course I can. Should I post it here?

Posting a link here will let other Drafts users access it and know that it relates to your topic. Posting a link elsewhere won’t provide any relevance to this topic.

At the moment all that is presented is an anecdotal point for an abstract action description.

Sorry for being a bit slow in getting what you where asking for. I have either never uploaded an action before or only a long time ago.

Anyway, here is the Link to my action.

I set it to “unlisted” because besides from what this thread is about it is not ready for public yet.

I have to add that the part of the second script that inserts the output of the action into the draft
is based on the Tag action. I don’t know if that action comes with Drafts or if I had downloaded from the Directory. Because if so, it was quite a while ago.

I could not get it to fail, but I’m running a beta and believe it has a related fix to a timing issue manipulating the updating the draft that is currently loaded in the editor.

That said, you can wait for the fix, but I would recommend you use the editor functions to manipulate the text instead, which are the preferred way to manipulate text currently loaded in the editor and not susceptible to this bug. They have better convenience methods to get/selected text, etc., and insert text without needing to slice and dice the full content of the draft.

Thanks for pointing me in the right direction.

Timing issue sounds great—because that would mean it’s not my long time not used and therefore quite dusted programming skills which caused the unstableness.

Like I said, the inserting part of the script was nicked from another script I can’t tell where it’s from or how old it is. I will look into the editor functions and try to improve the script.

Sorry for bothering you again. Since I did not find example scripts for moving and inserting in the Editor I am not sure if I am using the proper method now.

My task is simple: Insert text in Editor. If text was selected, replace it. If not, insert at cursor position. After inserting cursor position is after the inserted text. Nothing is selected. Editor is active. Draft is saved.

Does this do it?:

theText = "something";
theSelection = editor.getSelectedRange()[0];
editor.setSelectedRange((theSelection + theText.length),0);

Unlike the unreliable method (see above) this works. But it flashes, due to selecting I guess. Is there a better way?