Re: Trying to set the system volume in a Mail Rule AppleScript
Re: Trying to set the system volume in a Mail Rule AppleScript
- Subject: Re: Trying to set the system volume in a Mail Rule AppleScript
- From: Laine via AppleScript-Users <email@hidden>
- Date: Sun, 23 Apr 2023 15:21:26 -0500
> On Apr 23, 2023, at 12:20 AM, Christian Boyce via AppleScript-Users
> <email@hidden> wrote:
>
> I have a Mail Rule that announces certain emails out loud. For example, if I
> get an email from my Mom, the Mac will say “Mom sent you an email.”
>
> I want to set the volume in the rule’s script.
>
> I know how to set the volume— I can do it in a script like this:
>
>
> use AppleScript version "2.4" -- Yosemite (10.10) or later
> use scripting additions
> set oldVolume to output volume of (get volume settings)
> set volume output volume 10
> delay 10
> set volume output volume oldVolume
>
> If I have System Preferences open, and showing the Sound settings, I can
> watch the slider move and then move back after running this script. So I know
> how to set the sound level.
>
> But… in a Mail Rule that triggers an AppleScript, I find the “set volume
> output volume 10” does nothing at all.
>
> The script for a Mail Rule has to be something like this:
>
> using terms from application "Mail"
> on perform mail action with messages theMessages for rule theRule
> set this_document to open for access
> ("/Users/cboycemacpro/Desktop/myspanishwords.html") with write permission
> set the_content to read this_document
> --display dialog the_content
> repeat with eachMessage in theMessages
> — do stuff here
> end repeat
> close access this_document
> end perform mail action with messages
> end using terms from
>
> I put my sound-setting script step above “using terms from application
> “Mail”” and it has no effect. But that seems like the right place.
>
> So now I am wondering, can we not do things like that in a Mail Rule?
>
> Thanks for your help!
>
> This email sent to email@hidden
Please allow me to provide a more complete response.
The following AppleScript works for me in a mail rule. I’m running Mail in
Ventura (13.3.1, latest I think).
There are several contingencies needed to make the script work. For example the
“myspanishwords.html” file must exist on the Desktop and contain text that can
be displayed in the dialog (which I uncommented to facilitate testing). It
might help to verify the Mail rule’s functionality before specifying a "Run
AppleScript" action. I would suggest relaunching Mail whenever you make changes
to the script. I can confirm action of the script by using the menu bar Sound
control icon to examine Sound level once after the dialog has been quickly
dismissed, but while the indeterminate progress indicator (also in the menu
bar) continues to be displayed during script execution. Then I can confirm that
the volume setting has been restored to its original value after the progress
indicator has vanished.
use AppleScript version "2.5"
use scripting additions
property Loudness : "10"
property mywords : ((path to desktop as text) & "myspanishwords.html")
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
set this_document to open for access mywords with write
permission
set the_content to read this_document
display dialog the_content
repeat with eachMessage in theMessages
-- do stuff here
using terms from application "Script Editor"
set oldVolume to output volume of (get volume
settings)
set volume output volume Loudness
delay 10
set volume output volume oldVolume
end using terms from
end repeat
close access this_document
end perform mail action with messages
end using terms from
Best regards,
L. Lee
_______________________________________________
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