Skip to content Skip to sidebar Skip to footer

Jxa Move A Message To A Different Folder/mailbox

I'm stuck writing a JXA script using Apple's Script Editor. Essentially, I want to go through my inbox folder and move messages older than 44 days to an archive folder. I'm able

Solution 1:

Asked the question over on the Apple Discussion Board and got an answer.

Essentially, replace

// now what???

... with ...

Mail.move(messages[i], {to: archive});

Actually, the post over there had a more succinct way of doing it, but the above works too.

Solution 2:

Yikes. This task should be a simple two-line script [1]:

set cutoffDate to (current date) - 44 * days
tell application "Mail"to move (every message of inbox whose date sent < cutoffDate) to mailbox "Archive"

As for how to translate it to JXA – well, there's reasons I generally recommend sticking to AppleScript, including non-broken implementation, better (if still not ideal) documentation, and an established community of expert users who are always happy to explain and assist newcomers.

Or, even simpler, just set up a Mail Rule and avoid the need for scripting completely!


[1] Assuming you know how Apple event-based automation actually works, which 99.99% of programmers don't due to 1. Apple's own documentation failing utterly to explain it either clearly or correctly, and 2. Scripting Bridge and JXA crippling and obfuscating the crap out of it. Short version: it's not OOP, it's RPC plus simple first-class relational queries. (Slightly longer, if somewhat patchy explanation here.)

Post a Comment for "Jxa Move A Message To A Different Folder/mailbox"