Script pastes previous clipboard entry

I have a two step script. Step 1 runs a shortcutthat puts its output on clipboard.

Step two is the script.

var $content, cursorStart, cursorLength, cb;

$content = draft.content;
cursorStart = draft.selectionStart;
cursorLength = draft.selectionLength;
cb = app.getClipboard();

draft.content = $content.substr(0, cursorStart) + cb + $content.substr(cursorStart + cursorLength, $content.length)


The script pastes the contents of the clipboard before running the shortcut.

When the script is finished I can paste the correct contents. It’s as though step 2 starts before the Shortcut has finished.

If I run this multiple times in succession it pastes in the previous Shortcut result every time.

What could I be doing wrong?

I’m guessing that you haven’t set your first step to wait for a response.

If that isn’t it, can you share the whole action please? It is the context rather than the script that is important here.

That was easy. Thanks!

I did a few things with Drafts 4 but I have been away for awhile and am reorienting myself.