Moving cursor to end in "Prompt for User Input" window

I'm triggering a Prompt for User Input window when typing a number (using regular expression \d), and putting the typed number in the field using a variable whose default value is %TriggerValue%. I would like to be able to continue typing a few more numbers into the field in the prompt, and have those numbers appended to the %TriggerValue% number. However, %TriggerValue% number shows up highlighted in the window. I don't want the additional numbers I type to replace the %TriggerValue% number. I tried inserting an action to move the cursor to the end using "Type a Keystroke" with the right arrow key, but that didn't work. However, I CAN manually type the physical right arrow key and it does move the cursor to the end. I also tried using %|% in a few different places, but I can't seem to make it do what I want.

The issue here is that you have to execute the forward in the background.

Here is an example that implements the forward in the background. I have put a delay of 1.5 seconds in so you can see the effect.

Develop Macros.kmmacros (4.9 KB)

The VBAR Text Token only works in an "Insert text" Action.

But you can "Type a Keystroke: →" with an Action. The problem, as @fap points out, is that you can't use the Action after the "Prompt" Action because the prompt blocks execution until you respond to it -- and you can't use it before because it'll happen to early.

So you have to spawn a second macro, asynchronously, that waits until the prompt appears and then sends the keystroke. @fap used a hard-coded wait -- here's a version that uses AppleScript to wait for the prompt to appear:

...which you'd use with:

Both macros:
Prompt with Move.kmmacros (4.7 KB)

But I wonder if this is the best way? It depends on what you are doing, but I'd find it easier to type all the numbers in the same context (the document) and then bring up the prompt to select other values. You could do that by changing your trigger to "any numbers followed by a non-number" then stripping the last (non-number) character off the %TriggerValue%.

I've included a . as an "allowed" character, just in case...

Prompt v2.kmmacros (2.8 KB)

So you could type 123.4<space> to get a prompt with 123.4 pre-filled.

@Nige_S 's version is more robust and practical. I was showing that the principle is that it needs to happen asynchronously.

Thank you for the responses. That seems to do the trick. However, there are two other issues I'm noticing: Even before trying out the asynchronous Applescript (just bringing up the Prompt for User Input via \d), the screen flashes briefly. If, instead, I trigger the Prompt with a key combination (for example ctrl-shift-s), the screen doesn't flash. Not sure if that's something I need to worry about. The other thing I'm noticing happens when I do use the asynchronous Applescript. After successfully triggering the Prompt the first time, entering additional numbers and then hitting the return key, the next time I hit a number key, the screen just flashes and the Prompt dialog box does not appear. I have to hit a number key yet again to make it come up. At the moment, I'm using a workaround by putting a dummy keystroke as the last step in the macro, but I'm guessing that shouldn't be necessary.

That may be an artefact of the character deletion (if you have that set) followed by the Prompt appearing but, more often it's the app/OS indicating that you've pressed a "normal" key in a non-text entry context.

This sounds like two separate issues:

  1. The flash is probably indicating the non-text entry context (as above)
  2. The macro isn't triggering -- there seems to be an issue where a repeat of the typed string doesn't fire the trigger unless something happens in-between. That something can be a keystroke, but also switching to another application and back, or another window (and probably other things). Unfortunately, interacting with the KM prompt doesn't count -- I assume for a similar reason as to why you can't use typed string triggers in KM prompts.

I've not seen point 2 mentioned before -- but it would be an unusual typed string triggered macro that didn't do something (inserting text, a context change) in the typed-to window and would also be immediately followed by another typed string trigger.

You'll need to post your macro for more detailed help (instructions here), including an explanation of what you're trying to do and the context in which you want to do it.

But I can't help thinking that this is one of those rare times when an unmodified hot key trigger will be the way to go:

...etc