• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Scripting El Capitan Mail – Not All Bad News
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Scripting El Capitan Mail – Not All Bad News


  • Subject: Scripting El Capitan Mail – Not All Bad News
  • From: Christopher Stone <email@hidden>
  • Date: Sat, 03 Oct 2015 10:10:01 -0500

Hey Folks,

Hot damn!

While I really want to be able to script this natively, I'll settle for the fact that I can make it work with a little scripting and a little GUI-Scripting.

I was not able to get it working on Mavericks and didn't try on Yosemite, since I only had the latter installed for a couple of months.

This script automates the creation of an email where I forward a subscription I get out to a group of friends and takes nearly all the work out of it.  (See 'Task' in script for details.)

On my system I'll run it from Keyboard Maestro and add a couple of goodies.

KM can set the system find pasteboard, so I can delete some text from a known anchor quite easily.

I can then reposition the cursor for text-entry.

Done.

When run from FastScripts the script run-time is about 0.75 seconds according to the LapTime osax, but real elapsed-time monitored with a stopwatch is about 1.5 seconds.

Running from Keyboard Maestro and adding the bits I wanted to the macro ups elapsed-time to about 2 seconds – waaay faster than I can do it by hand.

A decade ago I did massive preprocessing of replies in Eudora with AppleScript in both plain-text and html mail.  My script was over 1000 lines, and it ran in the blink of an eye on that old hardware.  That script's genesis came about when the first regex osax caught my attention back around '96 or '97, and the painful process of learning regular expressions began.  Not long after I was using it to make my email life much easier.

So.  This kludgy methodology is an incredible step backwards.

But.  Considering that I am using Apple Mail this script/macro is freakin' fantastic.  It will save me considerable time and effort and will leverage to similar tasks.

Using this technique it should be possible to create a rule-based reply-to, but I'll need to do some more testing before I'm confident.

NOTE: I am running Mail in the classic configuration, so if you're NOT don't be shocked if the script doesn't work for you.

--
Best Regards,
Chris

-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/10/03 06:00
# dMod: 2015/10/03 09:07 
# Appl: Mail, System Events
# Task: Reply to a subscription email.
#     : Set To-Field to group from Contacts.app.
#     : Set From-Address using keyboard shortcut from system-keyboard-prefs.
#     : Focus to email body.
#     : Enter salutation.
#     : Delete 2 lines.
#     : Select-all below the cursor.
#     : Remove quote-level 1 from selected body.
#     : Reduce selected-text-size by 2.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Mail, @System_Events
-------------------------------------------------------------------------------------------
tell application "Mail"
  set messageSelectionList to selection
  if length of messageSelectionList = 1 then
    set theSelectedMessage to item 1 of messageSelectionList
    tell theSelectedMessage to reply
    set bounds of front window to {407, 23, 1312, 1196}
  else
    return
  end if
end tell
-----------------------------------------------------------------------------------------
tell application "System Events"
  tell application process "Mail"
    set frontmost to true
    tell (first window whose subrole is "AXStandardWindow")
      delay 0.05
      keystroke "g" using {command down, control down} -- keyboard shortcut for from in sys-prefs.
      tell text field "To:"
        set value to ""
        set focused to true
        keystroke "mm" -- start of Contacts Group name.
        delay 0.2
        keystroke ";"
      end tell
      tell scroll area 1 to tell UI element 1
        set focused to true
        keystroke "hg " -- Typinator abbreviation.
      end tell
      keystroke "k" using {control down}
      keystroke "k" using {control down}
      key code 125 using {command down, shift down}
      keystroke "'" using {command down, option down}
      keystroke "-" using {command down}
      keystroke "-" using {command down}
    end tell
  end tell
end tell
-------------------------------------------------------------------------------------------

 _______________________________________________
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

  • Prev by Date: El Capitan Mail Issues
  • Next by Date: AppleScript (bug?) in iTunes on El Capitan
  • Previous by thread: El Capitan Mail Issues
  • Next by thread: AppleScript (bug?) in iTunes on El Capitan
  • Index(es):
    • Date
    • Thread