Re: Mail Rule problem.
Re: Mail Rule problem.
- Subject: Re: Mail Rule problem.
- From: Axel Luttgens <email@hidden>
- Date: Sat, 23 May 2015 16:14:50 +0200
> Le 23 mai 2015 à 08:08, Brian Christmas a écrit :
>
> G’day scripters
>
> I’ve got a small script called from a Mail Rule every time a new message arrives, that announces the arrival, and calls the main email processing application.
>
> When several sequential messages arrive, the script runs multiple times, resulting in ‘echoes’.
>
> I’ve add a condition using a time storing property that only allows the script to run every 10 seconds, and it works fine when run as a script or application, but the Mail Rule somehow treats it differently, and the echoes are persisting.
>
> Anyone know of a way or getting the Mail Rule to treat the script normally, thus restricting the speech to every 10 seconds, please?
>
> Regards
>
> Santa
>
> [ a long script ]
>
Hello Brian,
It seems the core of your problem may be summarized by this one:
property counter : 0
set counter to counter + 1
say counter
delay 1 — simulate some time consuming actions
Could you save it as a compiled script and attach it to a Mail rule, then see whether it works "as intended" when invoked from Mail.app?
I ask, because I don’t remember since when script properties are fully handled from within such a context[1].
This is the case here under Yosemite 10.10.3, so I’ll assume the same for your environment.
When Mail’s rule is triggered:
- the script, including its state, is read from the disk
- the script is run
- one second later, the script terminates and is saved back to the disk
Now, consider two "simultaneous" invocations of the rule.
This will launch two "instances" of the script, each running in its own context.
But it is almost sure those two instances will start with the same state, ie with the same values of their properties (or globals).
As a result, one can’t rely on script properties for synchronizing multiple runs of that script.
You could try to minimize (probably not fully avoid) your problem by making use of another source of shared state than script properties. For example by checking whether a file exists and to create it if it doesn’t, all of this being done at the very beginning of your script.
HTH,
Axel
[1] Under Yosemite, that context is an invocation of /System/Library/Frameworks/Foundation.framework/Versions/C/XPCServices/com.apple.foundation.UserScriptService.xpc/Contents/MacOS/com.apple.foundation.UserScriptService, then at least two invocations of osascript with undocumented arguments.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden