How to select arrangement loop with Javascript in M4L???

Jay Walker's icon

Hello,
I'm trying to automate exporting midi>audio via javascript, my current rabbit-hole! I'm trying:

- Pre-record some midi in arrangement view
- Set the arrangement loop programmatically
- Command-Shift-R (Export)
- Hit Enter

// Javascript to Set Arrangement Loop Start/End
liveSet = new LiveAPI('live_set');
liveSet.set('loop_start', 4*22.0);
liveSet.set('loop_length', 4);
    liveSet.set('loop', 1);

Problem: How can I "select" the loop before I export? Reasoning: when manually clicked, the loop is selected and exporting automatically sets the start and end of the rendering. When it's not selected, I get an arbitrary start/stop.

Here are screenshots to show the difference:

1. The arrangement loop is not clicked and not selected:


2. The arrangement loop is manually clicked: