Sunday, May 28, 2017

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

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

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: 3007

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: 5

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: 3007

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: 5

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

 

#6 2017-01-23 10:09:02 pm

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

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

Hi again, Yvan and everyone.
I'm suddenly having an odd issue... I just updated to MacOS Sierra 10.12.3, and when I invoke the wonderful script you authored, Mail hangs. The spinning beach ball appears and my only recourse is to force quit and relaunch. Manually forwarding works, but the AppleScript results in the freeze.
I feel foolish for updating so quickly, but didn't imagine there would be issues with Apple's own software. Has anyone seen any issues with AS and the new update?

Any advice or suggestions are much appreciated.

Thanks!

Crooner

Offline

 

#7 2017-01-24 02:30:21 am

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

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

Here the script behaves flawlessly as it did before with 10.12.2 and the 10.12.3 beta versions.

At first look there is nothing in com.apple.mail.plist able to fool the app but it costs nothing to try to drop it :
quit Mail
drag & drop the named preferences file onto the desktop
restart the app.

If it's inefficient you may try to repair permissions.
I know that the feature is no longer available in Disk Utility but it's available in the free Onyx.

Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) mardi 24 janvier 2017 09:25:54

Offline

 

#8 2017-01-24 10:23:54 am

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

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

Hi, Yvan.
Thanks for the fast reply! After I posted, It occurred to me to try a permissions repair. First I cleared PRAM and then used Onyx (I usually use Sierra Cache Cleaner, but, of course, the new OS update isn't yet compatible) and so far, so good! If the issue reappears, I'll try removing the plist file and see if that helps.

Thanks again for all your help!

Crooner

Offline

 

#9 2017-01-25 04:55:19 am

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

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

Thanks for the feedback.

Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) mercredi 25 janvier 2017 11:55:14

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.040 seconds, 11 queries executed ]

RSS (new topics) RSS (active topics)