Send Mail Using Stationery in Automator/AppleScript

Discussion in 'Mac Programming' started by raiderchic7, Jun 11, 2010.

  1. raiderchic7 macrumors newbie

    Joined:
    Jun 11, 2010
    #1
    Hi, I am a big fan of working smarter so I am trying to teach myself automator/ applescripts. There are a few things I'd like to automate but am not quite sure how... For example, as the family "electronics coordinator" I send out birthday/anniversary/upcoming events emails to all family members. I would like to set up a script where ical events trigger email to the address book group. The extra twist is that I like using many different mail stationery depending on the occasion.

    Any thoughts? Thank you in advance for any guidance you can provide.
     
  2. healeydave macrumors regular

    Joined:
    Jan 12, 2008
    #2
    Bump.

    Surprised there are no replies to the OP, I have a standard automator mail app running from iCal but it would be nice if there is a way to request mail to use a specific stationary form before the process hits the "Send Outgoing Messages" action. Anyone know if this is possible?
     
  3. Mactrillionaire macrumors regular

    Joined:
    Oct 16, 2010
    #3
    I am not aware if there are any applications out there that would automate this. It seems simple enough to implement, however. The current user's Calendars would be in directories of the form ~/Library/Calendars/*.calendar/Events/ where * is a programmatically calculated unique ID. To provide this functionality would only require parsing a few files to figure out which calendar is which (i.e., the defaults are 'Home' and 'Work', and you can add others as well).
     
  4. healeydave macrumors regular

    Joined:
    Jan 12, 2008
    #4
    Thanks for the reply, I admit I'm a total novice with Automator, but I'm having difficulties getting it to do simple stuff, so I am doubting its/my ability to do the harder stuff :)

    If I create a simple "iCal Find Events" action to find an event today with "@" in the title, that works (a basic event in my iCal exists with an email address as the title).
    If I then add a "Set Value of Variable" action with a new variable called "Recip", I assume the results of the previous action (which contains the email address) is entered into this variable.
    The next action "New Mail Message" will however not allow me to drop the "Recip" variable in any of the fields other than the "Subject" field!?!?!??!

    Not only that, but Automator seems really buggy, because if I step through the process, sometimes the "Recip" variable seems to populate with the email address, other times, the variable seems to be blank.

    If Automator's this intermittent, how can anyone rely on it??
     
  5. healeydave macrumors regular

    Joined:
    Jan 12, 2008
    #5
    Okay, I've found and excellent download which adds the ability to choose Mail Stationary in Automator via a new action called "Apply Mail Stationery Template", its available at the following link, look for the install hyperlink:

    http://www.macosxautomation.com/automator/examples/ex09/index.html

    That solves the original topic problem.

    Annoyingly, I cant figure out a real basic issue (I thought Apple ruled at making complex things simple!?!?!).

    All I want to do is, using the Automator action "New Mail Message", populate the "To:" field with a variable. This field only seemed to accept directly entered text, I want to pull a variable into this field because the script I'm trying to write will be emailing to a different email address every time.

    Aaaarrrggghh, wasted hours on what I thought would be a such a simple task.
     
  6. xreliable macrumors newbie

    Joined:
    Dec 4, 2008
    #6
    were you able to get that stationery automator to actually work? I can run new messages and other automations but this fails. I do have assistive devices enabled in Sys Preferences/Universal. I have some 3pd stationery could that be the problem?

     
  7. healeydave macrumors regular

    Joined:
    Jan 12, 2008
    #7
    It seems to, I edited one of the standard apple stationary's years ago to incorporate some photo's of our villa, I have it as the only stationary in the favorites category (so it was always quick & easy to pick when using it manually). I have it places after the "New Mail Message" action and before the "Send Outgoing Messages" action. With Category set to "Favorites" and Template Name set to "Air Mail", it works for me.
     
  8. xreliable macrumors newbie

    Joined:
    Dec 4, 2008
    #8
    a bummer for me then. I get errors no matter which stationery I choose in the properties.
    The error just says to check the properties.


     
  9. healeydave macrumors regular

    Joined:
    Jan 12, 2008
    #9
    hmmm, weird, there is so little to configure, I'm not sure whats causing that, as I sure you've checked the obvious like typo's in the category or template name fields.
    Unfortunately, Automator gives zero information when it comes to error's.

    One last thought, do you have xcode installed?

    I know it might seem overkill to have Apple's development software installed, but the tools are free, and I have found a number of useful utilities over the years that have always worked perfectly on my iMac where I have the dev tools installed but been problematic on other machines without.

    For the sake of around a Gb of space, I would never be without it now, it means I always have the pre-requisites covered if I download a new tool in development that requires local compiling before you can use it etc, so its a handy resource to have, even if your not a developer.
     
  10. ykubeb macrumors newbie

    Joined:
    Mar 11, 2015
    #10
    The variable scroll_A_index is not defined

    Hi, Im totally new to automator but Im trying to create/send group messages using stationary. Currently I'm just trying to make automator work with apple's stationery (no custom stuff) and it keeps prompting an error while running actions. "The variable scroll_A_index is not defined" can anyone help me out with this? I truly have no idea of how to set that up. Will appreciate any help you can provide.
     
  11. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #11
    Post a list of the actions in your workflow and the version of OS X you're using. Which action gives the error? Post a screenshot of the error.
     
  12. ykubeb macrumors newbie

    Joined:
    Mar 11, 2015
    #12
    Thank you so much for your reply! the actions in the workflow are:
    New Mail Message
    Apply Mail Stationery Template
    Find Contacts Groups
    Group Mailer
    Send Outgoing Messages
     

    Attached Files:

  13. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #13
    The Apply Mail Stationery Template action is old and utilizes the built-in Graphic User Interface Scripting architecture of Mac OS X. Replace the Apply Mail Stationery Template action with a Run AppleScript action and replace the on run {input, parameters} handler with the following :

    Code:
    on run {input, parameters}
    	
    	(* Your script goes here *)
    	set chosen_category to "Stationery"
    	set template_name to "Fun"
    	
    	set this_system_version to the system version of (system info)
    	
    	if this_system_version begins with "10.9" then
    		set scroll_area_A_index to 2
    		set scroll_area_B_index to 3
    		set os_version to "Mavericks"
    	else if this_system_version is greater than or equal to "10.10" then
    		set scroll_area_A_index to 2
    		set scroll_area_B_index to 3
    		set os_version to "Yosemite"
    	end if
    	
    	
    	activate application "Mail"
    	tell application "System Events"
    		tell process "Mail"
    			if not (exists window 1) then error "NO_WINDOW_ERROR"
    			tell window 1
    				set the_buttons to every button of toolbar 1
    				repeat with a_button in the_buttons
    					if value of attribute "AXDescription" of a_button is "Show Stationery" then
    						click a_button
    						exit repeat
    					end if
    				end repeat
    				set this_table to table 1 of scroll area scroll_area_A_index
    				if os_version is equal to "Mavericks" then
    					set the category_list to the value of static text of every row of this_table
    				else
    					set the category_list to the value of text field 1 of every row of this_table
    				end if
    				repeat with i from 1 to the count of the category_list
    					set item i of the category_list to (item i of the category_list) as string
    				end repeat
    				if the category_list contains the chosen_category then
    					repeat with i from 1 to the count of rows of this_table
    						if os_version is equal to "Mavericks" then
    							set this_category to (the value of static text of row i of this_table) as string
    						else
    							set this_category to (the value of text field 1 of row i of this_table) as string
    						end if
    						if this_category is the chosen_category then
    							select row i of this_table
    							exit repeat
    						end if
    					end repeat
    					
    					set the template_list to radio group 1 of scroll area scroll_area_B_index
    					set the button_titles to the title of every button of template_list
    					if the button_titles contains the template_name then
    						click button template_name of template_list
    					end if
    				end if
    				click a_button
    			end tell
    		end tell
    	end tell
    	return input
    end run
    Should work on Mavericks and Yosemite.
     
  14. kosz macrumors newbie

    kosz

    Joined:
    Jul 10, 2017
    #14
    Hi kryten2

    any hints how to make this script work on Sierra? scroll are returns error :(

    Thnx.

     
  15. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #15
    Hi,

    I'm still running Mavericks and Yosemite and have absolutely no intention on running Sierra in the near future. Something changed in the UI of the Mail application.

    Hints : Use UI Browser or Apple's Accessibility Inspector to see what changed.

    Info : http://pfiddlesoft.com/uibrowser/index.html
     
  16. kosz macrumors newbie

    kosz

    Joined:
    Jul 10, 2017
    #16
    I was able to make it work - the problem was that I had no new message window opened.
    Added this code before your script and now it works.

    Code:
    property lastWindowID : missing value
    
    tell application "Mail"
        set windowIDs to id of windows
        if windowIDs does not contain lastWindowID then
            set newMessage to make new outgoing message
            tell newMessage
                set visible to true
            end tell
            activate
            set lastWindowID to id of window 1
        else
            tell window id lastWindowID
                set visible to false
                set visible to true
            end tell
            activate
        end if
    end tell

    Do you know if there is any way to update the specific body content of the mail after loading it from stationery.
    I have an element inside and I can reach it (thnx to UI browser). I can also output its value using the dialog box.
    What I can't do is changing it and don't understand why.

    in my stationery I have this value placed like this:
    Code:
    <span contenteditable="true" apple-content-type="mBody" apple-content-name="mBody">paste text here</span>
    This works and outputs "The current value is: paste text here" via dialog
    Code:
    set mBody to static text 1 of text area 1 of group 7 of UI element 1 of scroll area 1
    set theDialogText to "The current value is: " & value of mBody
    display dialog theDialogText
    --> Result: {button returned:"OK"}
    But this doesn't:
    Code:
    set mBody to static text 1 of text area 1 of group 7 of UI element 1 of scroll area 1
    set value of mBody to "bla bla bla"

    Any ideas?
     
  17. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #17
  18. Osty macrumors 6502a

    Joined:
    Jul 15, 2008
    Location:
    Melbourne, AU
    #18
    I actually had the same problem when wanting a means to automate email newsletters. Got it working but it felt too hacky. Ended up creating a Workflow on my iPad and using that instead.
     
  19. kosz macrumors newbie

    kosz

    Joined:
    Jul 10, 2017
    #19
    Hi Osty,
    can you please share your workflow?

    I still couldn't get the body of the message update the variable inside (

    Thnx
     
  20. Osty macrumors 6502a

    Joined:
    Jul 15, 2008
    Location:
    Melbourne, AU
    #20

    Will do, mate as soon as I get home from work. I wonder if I can do it here or just use the Workflow website...
     

Share This Page