Monday, January 23, 2017

#1 2017-01-09 05:33:25 pm

crooner
Member
Registered: 2017-01-09
Posts: 3

Help Needed: Trying to create a couple of scripts for Mail.

Hello to all.
I've only lightly dabbled in AppleScript in the past and am currently trying to create a couple of seemingly simple scripts to redirect a selected message (or multiple messages, if possible) to a pre-set e-mail address. I'm using apple Mail in MacOS Sierra 10.2.2.

I've looked in the scripting dictionary and tried using the redirect command as well as the mailto, but I never get past two lines before the compiler tells me I'm on the wrong track.

I thought the structure would look something like this:

tell application Mail
redirect selected message
mailto <email@emailadress.com>
end tell

Obviously, this didn't sit well with Script Editor.

Ideally, I'd like to have the scripts just sit in AppleScript menubar menu ready to select and automatically redirect the selected message to an address written into the script.

Can anyone help with this?

Thanks so much!

Offline

 

#2 2017-01-10 03:22:10 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 2743

Re: Help Needed: Trying to create a couple of scripts for Mail.

You may try :

Applescript:

set destAddress to "email@emailadress.com" # Edit to fit your needs

tell application "Mail"
   activate
   set theMessages to the selection # one or several message(s) selected
   repeat with aMessage in theMessages
       set newMessage to redirect aMessage
       tell newMessage
           make new to recipient with properties {address:destAddress}
       end tell
       send newMessage
   end repeat
end tell

Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) mardi 10 janvier 2017 10:19:03

Last edited by Yvan Koenig (2017-01-10 05:20:33 am)

Offline

 

#3 2017-01-10 08:32:52 am

crooner
Member
Registered: 2017-01-09
Posts: 3

Re: Help Needed: Trying to create a couple of scripts for Mail.

Yvan,
THANKS! Your script worked great. I truly appreciate your help. Looking at the script it became painfully obvious that it would have taken me possibly a decade of research to arrive at that language. Your command of AppleScript is impressive.

All the best to you!

crooner

Offline

 

#4 2017-01-10 11:21:17 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 2743

Re: Help Needed: Trying to create a couple of scripts for Mail.

Thanks for the feedback.

I was not really satisfied by the original code.

Here is a revised version:

Applescript:

set destAddress to "email@emailadress.com" # Edit to fit your needs

tell application "Mail"
   activate
   repeat with aMessage in (get the selection)
       tell (redirect aMessage)
           make new to recipient with properties {address:destAddress}
           send it
       end tell
   end repeat
end tell

Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) mardi 10 janvier 2017 18:18:54

Offline

 

#5 2017-01-10 09:15:22 pm

crooner
Member
Registered: 2017-01-09
Posts: 3

Re: Help Needed: Trying to create a couple of scripts for Mail.

Thanks again, Yvan.
The revised script works great.

Your help is very much appreciated!

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.037 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)