JXA to order Reminders

JXA seems to work for some things in Reminders, but I can't seem to find a way to change the order of reminders in the list and there doesn't appear to be any documentation about that.

The .move() command doesn't seem to work (seems to delete) and the .duplicate() command seems to move not actually duplicate.

How can I move a reminder task within a list using JXA?
Sorry, but you’re SOOL. Amongst their many frustrating defects, neither JXA nor Scripting Bridge allow you to construct insertion location specifiers, so it’s impossible to express commands such as move X to beginning/end of Y or move X to before/after Y.

(There’s no technical reason why JXA and SB should be so crippled: appscript, SwiftAutomation, and nodeautomation all implemented AppleScript-quality AE bridges just fine. The Mac Automation team just botched them is all. And now that department’s disbanded, JXA and SB are dead tech walking.)

Stick to AppleScript; the language may be awful but it’s the only nominally supported solution that speaks Apple events right.
I tried this in AppleScript as well and had similar problems. Do you have an example of moving a reminder in AppleScript?
Swift code using EventKit would actually be ideal now since I'm having to build an app to address the TCC issues.
For example the following script just deletes item 2 instead of moving it (the same thing happened when I use the JXA .move() function):

Code Block
tell application "Reminders"
activate
tell list "Test"
move reminder 2 to after reminder 5
end tell
end tell

Yep, always test first in AppleScript to see if it works there. I can confirm there’s a bug in Reminders.app on 10.14; I expect it’s the same on 10.15. The following move command removes the specified element[s] from the collection but fails to insert it at the new position:

Code Block
-- (manually create some reminders named "test-1", "test-2", "test-3", etc)
tell application "Reminders"
move reminder "test-2" to beginning of reminders
end tell


The app returns error -10000, “AppleEvent handler failed”, and the reminder named "test-2" disappears entirely. That’s a significant (data-destroying) bug.

Ditto for:

Code Block
move reminder "test-2" to end of reminders
move reminder "test-3" to before reminder "test-2"
move reminder "test-1" to after reminder "test-3"


(There is an art to implementing reliable move and duplicate commands that don’t **** up with “off-by-one” and other bugs. Alas, the Cocoa Scripting framework upon which most apps’ scripting support is built is somewhat clunky, and app developers rarely test their scripting support as thoroughly as they should.)

You can try filing a bug report on Reminders.app, though given Apple has all but abandoned AppleScript automation there’s no guarantee it’ll be fixed any time soon, or ever.

(Note that JXA’s broken reference forms are a completely unrelated defect, and since JXA is completely abandoned I wouldn’t even bother filing bug reports on that. I already tried, and it was a waste of my time. Again, stick to AppleScript to minimise your pain.)

So no luck with JXA or AppleScript. I've created an app using Swift (at least that should be supported!).

Any idea how to modify the manual order of reminders in the Reminders.app using Swift?

I have gotten to a point where I can get a reminders list and move them to other lists by changing the .calendar property, however even if I move them in reverse order (move Task 2 and then move Task 1), they appear in the second list in Task 1 then Task 2 order. I suspect there is some property indicating the order or weight. When I used JXA to duplicate an item from the middle of one list to another list (which actually moved instead of duplicating), it appeared in the middle of the destination list and not at the end.

As a workaround, I'd be even okay if there was a way to UI script, however, I can't find a way to re-order rows via UI scripting.
Apparently this can't be done at all from EventKit so I'm back to a scripting solution. I have figured out how to do the sort via script, so if I could figure out how to drag a row to reorder, that would work.

Code Block javascript
var app = Application('Reminders');
app.includeStandardAdditions = true;
var remindersLists = app.lists;
var remindersList = remindersLists.byName('Test');
app.activate();
remindersList.show();
menuItemClick("Reminders", ['View','Sort By','Title']); /* just in case it's already sorted by Priority */
menuItemClick("Reminders", ['View','Sort By','Priority']);


At this point, if I could drag a row to another location, that would "lock in" the sort order and be an acceptable (if kludgy) workaround.

How can I drag a row to another location within a list using UI scripting?

Ideally I could just move a row to another location to lock in the order via scripting instead of UI scripting but I'll take whatever I can get.
JXA to order Reminders
 
 
Q