Wednesday, November 20, 2019

#1 2006-03-10 08:58:53 am

tarcus
Member
Registered: 2006-03-10
Posts: 1

Read New Mail Message

Hi there,

i want to make a script which is being executed everytime a new mail gets in. It should read the mail via speech.
In Mail Rules i set up every mails with "@" in their name. So its being loaded every time a mail comes in, not a problem.
But now the script makes me some problems. I first decided to take the AppleScript  "Speak Sender and Subject" which works fine for me. But i dont get the script speaking the message too. Here is the Script:

Applescript:


using terms from application "Mail"
   on perform mail action with messages selectedMsgs
       -- See Mail's AppleScript dictionary for the full documentation on the
       -- 'perform mail action with messages' handler.
       set logString to "" & return
       tell application "Mail"
           set selCount to (count of selectedMsgs)
           if selCount is equal to 0 then
               set logString to logString & "There are no selected messages."
           else if selCount is equal to 1 then
               set logString to logString & "There is " & selCount & " selected message."
           else if selCount > 1 then
               set logString to logString & "There are " & selCount & " selected messages."
           end if
           repeat with counter from 1 to selCount
               set msg to item counter of selectedMsgs
               set theSubject to subject of msg
               set theSender to sender of msg
               set theSender to extract name from theSender
               set logString to (logString & tab & "Message " & counter as string) & " from: " & theSender & ", subject: " & theSubject & ". "
           end repeat
       end tell
       if length of logString > 0 then
           say logString
       end if
   end perform mail action with messages
end using terms from

-- If run as an ordinary script, instead of directly from the Scripts
-- menu, it will call the default handler instead.
using terms from application "Mail"
   on run
       tell application "Mail" to set sel to selection
       tell me to perform mail action with messages (sel)
   end run
end using terms from

Thanks for help in advance

Model: Powerbook G4 1.67Ghz
AppleScript: 2.1.1
Browser: Safari 417.8
Operating System: Mac OS X (10.4)


Filed under: mail

Offline

 

#2 2019-08-11 05:25:37 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 714

Re: Read New Mail Message

Nice script, thanks. I needed to make only 2 changes to your code so that it “spoke” completely.

Applescript:


using terms from application "Mail"
   on perform mail action with messages selectedMsgs
       -- See Mail's AppleScript dictionary for the full documentation on the
       -- 'perform mail action with messages' handler.
       set logString to "" & return
       tell application "Mail"
           set selCount to (count of selectedMsgs)
           if selCount is equal to 0 then
               set logString to logString & "There are no selected messages."
           else if selCount is equal to 1 then
               set logString to logString & "There is " & selCount & " selected message."
           else if selCount > 1 then
               set logString to logString & "There are " & selCount & " selected messages."
           end if
           repeat with counter from 1 to selCount
               set msg to item counter of selectedMsgs
               set theSubject to subject of msg
               set theSender to sender of msg
               set theContent to content of msg
               set theSender to extract name from theSender
               set logString to (logString & tab & "Message " & counter as string) & " from: " & theSender & ", subject: " & theSubject & ". " & theContent
           end repeat
       end tell
       if length of logString > 0 then
           say logString
       end if
   end perform mail action with messages
end using terms from

-- If run as an ordinary script, instead of directly from the Scripts
-- menu, it will call the default handler instead.
using terms from application "Mail"
   on run
       tell application "Mail" to set sel to selection
       tell me to perform mail action with messages (sel)
   end run
end using terms from

Last edited by KniazidisR (2019-08-11 05:29:15 am)


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)