Dorico LUA script runs on my MAC, but does not update the Dorico score

I am trying to automate setting rehearsal marks in my score.
The following Dorico LUA script runs on my MAC, but does not update the Dorico score. I see the debug output is correct in Dorico Script console.

local app=DoApp.DoApp()
– Simulate a delay by looping for a small amount of time
function wait(seconds)
local start = os.time()
while os.time() - start < seconds do
– Do nothing, just wait
end
end

– Move directly to a specific bar and insert a rehearsal mark
function moveToBarAndInsertRehearsalMark(barNumber)
print("Moving to bar " .. barNumber)
app:doCommand([[Navigate.GotoBar]] .. " " .. barNumber)
– Wait a moment to allow the UI to update
wait(2.0) – Adjust this delay if needed
print("Inserting rehearsal mark at bar " .. barNumber)
app:doCommand([[WriteMode.CreateRehearsalMark]])
end

– Main script starts here
– Switch to Write Mode
print(“Switching to Write Mode”)
app:doCommand([[Window.SwitchToWriteMode]])
wait(2.0) – Small delay after switching modes

– Select the start of the flow (bar 1)
print(“Selecting start of the flow (bar 1)”)
app:doCommand([[WriteMode.SelectStartOfFlow]])
wait(2.0) – Small delay to allow Dorico to process the selection

– Insert rehearsal mark at bar 1
print(“Inserting rehearsal mark at bar 1”)
app:doCommand([[WriteMode.CreateRehearsalMark]])

– Move to bar 9 and insert rehearsal mark
moveToBarAndInsertRehearsalMark(9)

– Move to bar 17 and insert rehearsal mark
moveToBarAndInsertRehearsalMark(17)

print(“Script finished!”)

Debug:
Switching to Write Mode

Selecting start of the flow (bar 1)

Inserting rehearsal mark at bar 1

Moving to bar 9

Inserting rehearsal mark at bar 9

Moving to bar 17

Inserting rehearsal mark at bar 17

Script finished!

Switching to Write Mode

Selecting start of the flow (bar 1)

Inserting rehearsal mark at bar 1

Moving to bar 9

Inserting rehearsal mark at bar 9

Moving to bar 17

Inserting rehearsal mark at bar 17

Script finished!

Am I doing something wrong in LUA scripting?

Thanks in advance,
Gregg

Are you sure that Navigate.GoToBar actually selects something in that bar?

I would break it down into small chunks, and check that each part does what you expect.

Also: are you setting rehearsal marks in the same bars in more than one flow/project?

If you have to change the bar numbers in the script when you run it, I would have thought that it would be just as quick to press Shift A at the relevant point. :grin:

That is the issue. Navigate.GoToBar does not select anything, only changes view. I was hoping that there was a database of notes, where I could select the first quarter note or rest in any bar.