slotguru

Q: Applescript for Mail Not Working Since Upgrade to El Capitan

I have an Applescript to forward emails to Evernote that has stopped working since I upgraded to El Capitan. It opens the new message but does not update the email address or subject and does not send. Again, this worked prior to upgrading to El Capitan. Any help is much appreciated.

 

 

set theAddress to "email@evernote.com"

display dialog "Doc Name" default answer ""

set DocName to text returned of result

 

display dialog "Tags" default answer ""

set Tags to text returned of result

 

try

  tell application "Mail"

  set theSelection to selection

  if DocName = "" then

  set thesubject to subject of item 1 of theSelection & " " & Tags

  else

  set thesubject to DocName & " " & Tags

  end if

  set theForwardedMessage to forward (item 1 of theSelection) with opening window

 

  tell theForwardedMessage

  make new to recipient at end of to recipients with properties {address:theAddress}

  set subject to thesubject

  end tell

  activate

 

  delay 1

  send theForwardedMessage

  end tell

 

end try

OS X El Capitan (10.11)

Posted on Oct 18, 2015 3:23 PM

Close

Q: Applescript for Mail Not Working Since Upgrade to El Capitan

  • All replies
  • Helpful answers

  • by Camelot,

    Camelot Camelot Oct 18, 2015 10:55 PM in response to slotguru
    Level 8 (47,233 points)
    Mac OS X
    Oct 18, 2015 10:55 PM in response to slotguru

    Well, the first problem is that recipient lists no longer need (or, indeed, work) with the '... at end of...' specifier, so you can just:

     

      make new to recipient with properties {address:theAddress}


    The second problem, though, appears to be a bug. Even with a valid recipient list the script fails on the line:


    set subject to thesubject


    Which, as far as I can tell, is a bug - you can't change the subject of a forwarded message. It's fine if you create a new message, and if you manually forward a message you can change the subject, but you can't change it via AppleScript.

     

    The best I could come up with is a tacky UI scripting 'solution':

     

      tell theForwardedMessage

      make new to recipient with properties {address:theAddress}

      end tell

      activate

      tell application "System Events"

      keystroke tab using shift down

      keystroke thesubject

      end tell


     


  • by slotguru,

    slotguru slotguru Dec 31, 2015 2:15 PM in response to Camelot
    Level 1 (0 points)
    Dec 31, 2015 2:15 PM in response to Camelot

    I know this is a very delayed response, but I appreciate the help here. I don't care if it's tacky as long as it works. Your solution does update the subject but the message still does not send. Any idea why "  send theForwardedMessage" isn't working and how to correct it (or workaround)?

     

    Thanks.

  • by ChisolmLee15,

    ChisolmLee15 ChisolmLee15 Aug 28, 2016 9:44 AM in response to slotguru
    Level 1 (8 points)
    Aug 28, 2016 9:44 AM in response to slotguru

    tell application "Mail"

    tell application "System Events"

            keystroke "d" using {command down, shift down}

        end tell

    end tell