Mail rules with javascript instead of applescript

In Mac email rule, I try to run javascript instead of applescript. This was set in Mail Rules using JavaScript to automate instead of AppleScript , but the answer does not work for me!

I tried to simplify the code as much as I can. So, the following applescript works just fine:

on perform mail action with messages theMessages say "running!" end perform mail action with messages 

but equivalent javascript is not working.

 function performMailActionWithMessages(messages) { app = Application.currentApplication() app.includeStandardAdditions = true app.say ("running") } 

Edit Here are my rule options

mail2.scpt

rule configuration

+1
source share
1 answer

I do this without getting the application. Try something like ...

 // ObjC.import('Cocoa') ObjC.import('stdlib') var program="/usr/bin/say" function performMailActionWithMessages(messages) { say("running") } function say(what){ var command = program + " '"+what+"'" console.log(command) $.system(command) } 

I'm not sure you need cocoa. You probably need stdlib.

+1
source

Source: https://habr.com/ru/post/987219/


All Articles