Skip to content

Instantly share code, notes, and snippets.

@SKaplanOfficial
Created September 7, 2023 04:34
Show Gist options
  • Save SKaplanOfficial/c0a5ce0c43ebce021aaa20328d9fb84d to your computer and use it in GitHub Desktop.
Save SKaplanOfficial/c0a5ce0c43ebce021aaa20328d9fb84d to your computer and use it in GitHub Desktop.
Example JXA script to perform mail actions. Place the script in ~/Library/Application Scripts/com.apple.mail/.
function performMailActionWithMessages(messages, options) {
// do stuff, e.g.:
const app = Application('System Events');
app.includeStandardAdditions = true;
// messages are provided as a list
app.displayDialog(messages.map((message) => message.subject()).join(', '))
// options are provided as an object with two properties: inMailboxes and forRule
// both options can be undefined
if (options.inMailboxes) app.displayDialog(options.inMailboxes.map((mailbox) => mailbox.name()).join(', '))
if (options.forRule) app.displayDialog(options.forRule.name())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment