Applescript for mail rule

I found this on Mactech. All I did was add the line "make new outgoing........", well, it does NOT work. What do you have to do to make Mail trigger an applescript. All I want to do is when I an email reminder, to just make a new email message with Happy Birthday in the Subject. I'll click the stationary and add a birthday background. Any help would be appreciated.
using terms from application "Mail"
on perform mail action with messages theSelectedMessages for rule theRule
repeat with a from 1 to count theSelectedMessages
make new outgoing message with properties {visible:true, subject:"Happy Birthday", content:"Happy Birthday "}
end repeat
end perform mail action with messages
end using terms from

sorry but your suggestion did NOT work. Here is what I wrote and it did NOT make a difference the script will NOT generate an outgoing message.
using terms from application "Mail"
on perform mail action with messages newMessages
repeat with newMessage in newMessages
tell application "Mail"
set senderName to (extract name from sender of newMessage)
say "You've just received an email from " & senderName
say (subject of newMessage) as string
if (subject of newMessage) contains "birthday" then
tell application "Mail"
activate
make new outgoing message with properties {visible:true, subject:"Happy Birthday", content:"Happy Birthday "}
end tell
end if
end tell
end repeat
What I was able to do was embed a line of code to call another script that does successfully create an out going message. Here is the successful script.
using terms from application "Mail"
on perform mail action with messages newMessages
repeat with newMessage in newMessages
tell application "Mail"
set senderName to (extract name from sender of newMessage)
say "You've just received an email from " & senderName
say (subject of newMessage) as string
end tell
end repeat
tell application "Finder"
open "Macintosh HD:Users:Shawn:Documents:Applescripts:Mail scripts:make outgoing email happy birthday5.app"
end tell
end perform mail action with messages
end using terms from
here is the make birthday5 app
tell application "Mail"
activate
make new outgoing message with properties {visible:true, subject:"Happy Birthday", content:"Happy Birthday "}
end tell
Now when I get my birthday reminder, according to the "Rule" set up in preferences, if the subject contains "birthday" the script will read the name and subject and generate an outgoing message with Happy Birthday in the Subject and Body.....all I have to do is add some birthday stationary, type in a sappy line and viola, done. See why I love Macs so much.

Similar Messages

  • Export mail message as PDF Applescript for mail rules

    I have looked everywhere for this and found nothing. I don't have 40 hours to learn applescript myself but from the little I do know this should be possible. Probably easy.
    I want to created an applescript to run as a mail rule. I want the script to export the message as a PDF and move that PDF to a specified folder. Hazel can take it from there.
    for instance:
    Fedex sends me a email message that my shipment has been delivered.
    mail rule kicks in and runs the script
    script creates a PDF of the message
    message is moved to "fedex delivered" folder

    I found a workaround, though there must be something neater.
    I added this before my script
    tell application "System Events"
              tell process "Mail"
                        tell menu bar 1
                                  tell menu bar item "View"
                                            tell menu "View"
                                                      tell menu item "Sort By"
                                                                tell menu "Sort By"
                                                                          click menu item "Subject"
                                                                end tell
                                                      end tell
                                            end tell
                                  end tell
                        end tell
              end tell
    end tell
    then the same except "Date" instead of "Subject".
    My script does what i want now.

  • Using AppleScript in Mail Rules

    I can't figure out how to edit an AppleScript for Mail to perform the following:
    1) After moving a filtered incoming message to a prescribed folder (can do this easily), open the message in a new window (or go to the folder and show message).
    2) Before sending a message, specify a folder to store the outgoing message. This could be done via bcc in Eudora, and can be done separately in Entourage, but I don't know enough to figure out how to do it in Mail.
    Thanks for any suggestions.

    gauthier,
    1) After moving a filtered incoming message to a prescribed folder (can do this easily), open the message in a new window (or go to the folder and show message).
    You might want to take a look at the Open Message and Open Mailbox scripts available from Mail Scripts - they should do exactly what you are looking for:
    http://homepage.mac.com/aamann/
    2) Before sending a message, specify a folder to store the outgoing message. [...]
    This is not possible in Mail since you cannot hook into the sending action to perform actions before sending (and rules per se don't apply to outgoing messages). However, you might check out the Filter Sent Messages script from the above referenced Mail Scripts as somewhat of a work-around.
    Andreas

  • Applescript for Mail Question

    Is it possible to create an Applescript for Mail, that, when an email with a specific subject line arrives in my inbox, an attached photograph would get sent immediately in response to the person who sent the email.  The subject lines would vary (e.g., people_1, or, places_16).  Every subject line would have a corresponding photo located somewhere on my hard drive (there would be hundreds of possibilities - the catalogue would be concentrated in one place).  So, for example, when "places_21" hits my Mail in box, an email would be generated in response, automatically, with a photo (places_21) attached.  Thank you!  Marcos

    Actually, it's not that hard to do, it's just that there are a lot of use cases, and a lot of caveats to consider.
    For example, do you intend/expect to work from a predefined list of image file names? Or do you want/expect to react to any filename that's requested?
    You say that the files would be 'somewhere on my hard drive'... how does the script know where to look? How does it resolve filename conflicts? What should happen if a file can't be found?
    As fane suggests, you should also consider an audit log, so you can see who asked for what, and when, along with errors that occurred on the way.
    So it's entirely do-able, just a lot of questions to answer before you get started.

  • AppleScript for mail merge

    What is AppleScript for mail merge

    AppleScript is a programming language that is tied to certain Applications that support it. Pages v5.5.1 has a scripting dictionary of the terms it will support via AppleScript. Apple's answer to not including Mail Merge functionality in Pages v5.5.1 is for individual users to roll their own, download an example and adapt it, or use another application with built-in Mail merge features.
    See my previous post to you.

  • Applescript: creating mail rules

    Hi Community,
    I can't find the syntax for creating a mail rule in applescript anywhere on the web. If someone could just post all the different options in one snippet (Move Message, Play Sound, Set Color, Delete Message, and run applescript) that would be awesome. Thanks!

    I agree with twtwtw.  Most of the rules I use simply organize the inbox into separate mailboxes. So with a list of 150 or so students each semester, it would be great to have this script work..it creates the rules, one for each student number,  but then the rule won't move the incoming messages.  Hmm...
    So if anyone figues out why, it would be great to let us know! 
    tell application "Microsoft Excel"
              set hpath to "Macintosh-HD:Users:bg:20f11:Hmwk:graded:"
              set theGrades to open workbook workbook file name "Macintosh-HD:Users:bg:20f11:20f11_grades.xlsx" update links do not update links
              set email_list to value of every cell of range "e_mail"
              set theMailbox to "20f11"
      activate
              set sn to value of every cell of range "sn"  --sn is student number
    end tell
    tell application "Mail"
              repeat with j from 1 to length of sn
                        set newRule to make new rule at end of rules with properties {name:item j of sn), enabled:false}
                        tell newRule
      make new rule condition at end of rule conditions with properties {rule type:from header, expression:item j of email_list), qualifier:does contain value, move message:mailbox theMailbox}
                end tell
              end repeat
    end tell

  • Running AppleScript from Mail rules

    Hi.
    I'm pretty new to this, so sure it's a basic question....
    I've created An AppleScript that calls an Automator application.  This runs fine if I open the script in the editor and click run.
    I've now created a mail rule which should run this script if a mail is received with defined subject, but it doesn't....
    Whatever I try, it's just not running the script.
    Any help?

    Yes.
    tell application "iTunes"
      quit
    end tell
    delay 60
    tell application "iTunes"
      activate
    end tell
    Change 60 seconds in delay to the delay you need.
    (still might not work as a Mail Rule, but give it a try)

  • Looking for Mail Rules Management Tools and Advice

    I missed article #302257 Mac OS X 10.4.3: Some Mail rules may be disabled after syncing with .Mac
    Now I have a big mess with lots of mails being directed to the Trash
    unintentionally. I having difficulty sorting this all out.
    I'm synching among 3 machines.
    I had started with 153 rules. Without realizing it (see the article above) that number almost doubled but I was puzzled that some rules got turned off. Having so many rules I failed to check for duplicates at first - not that it really should have matter except to slow down the evaluation process a bit.
    Rules seemed to be scrattered more widely than they were originally due to the syncing anomoly. But it is hard to get the "big view" with so many rules.
    Last night I eliminated the dups on my main home machine. I tried to reorganizing for logic's and clarities sake. But made the mistake of renaming several rules. Now it seems that this caused problem, too.
    Is there a better way or, even better, an application that works with Mail.app rules that can help one organize, helps tests the rules, and helps one make sure that the stop evaluating rules drop down is selected?
    If there a non destructive way to open and print out the Mail.app rules file in an understandable way? And then use that information to write better mail rules?
    Thanks in advance.
    Frank
    G4 933, G4 Powerbook 667   Mac OS X (10.4.3)   1 Gig RAM

    Jan-David,
    1) Have a look at Cantemo Portal which also has a Final Cut Server migration tool.
    http://cantemo.com/index.html
    André Aulich (moosystems) has built the FCSvr migration tool, and the integration with Archiware P5 Archive:
    http://moosystems.com/products/moofs/
    Check out the YouTube videos for FCP X and Premiere integration:
    http://www.youtube.com/watch?v=XnjBbDajC6U
    http://www.youtube.com/watch?v=GTawWFiIyTw
    2) And you might also check out Axle Video:
    http://www.axlevideo.com
    This is on the lower end. It has fewer features, but it aims to be a simple MAM, not an Enterprise tool.
    I don't think there is a Final Cut Server migration tool yet, but that might be coming soon.

  • Cant send mail via applescript with mail rule

    I created a script that would work as follows:
    I send myself an email. The mail rule opens up an apple script that will take a picture using the isight camera and then email it back to me. It works fine in script editor. When i run it via mail.app it takes the picture but it wont email it back to me.
    Here is my script:
    do shell script "~/Documents/EmailScripts/isightcapture ~/Documents/EmailScripts/snap.jpg"
    tell application "Mail"
    set addrVar to "[email protected]"
    set subjectvar to "Macbook Pic"
    tell application "Finder"
    set the target_file to alias "Macintosh HD:Users:ak406:Documents:EmailScripts:snap.jpg"
    set bodyvar to "Picture from Macbook"
    end tell
    set composeMessage to (make new outgoing message)
    tell composeMessage
    make new recipient at beginning of to recipients with properties {address:addrVar}
    set the subject to subjectvar
    set the content to bodyvar
    tell content
    make new attachment with properties {file name:target_file} at after the last word of the last paragraph
    end tell
    end tell
    send composeMessage
    end tell
    Thanks for the help.

    Hi ak406
    Just tested your script here, less the do shell script part and it worked perfectly from my mail app.
    Budgie

  • Applescript for mail error can't get message id

    I have an applescript (found on internet) for Mail 4.5 that deletes messages in "on my mac" mailbox "Deleted Inbox" that are older than 120 days. The script runs from an iCal daily event. I drag messages from Inbox to "Deleted Inbox" when I don't want the message in Inbox, but I want to save the message for 120 days before deleting it. The script sometimes runs successfully, and sometimes gives error "Mail got an error: Can't get message id xxx of mailbox "Deleted Inbox"". Then in Mail, I "Mailbox / Rebuild" that mailbox, and run the script manually without error. How can I avoid that error? The script is essentially:
    tell application "Mail"
              set OldStuff to every message of mailbox TheBox where date received of it < OldDate
              repeat with ThisMessage in OldStuff
        delete ThisMessage
              end repeat
    end tell
    Thanks for any help.
    Ken

    How can I avoid that error?
    I don't actually know how you can avoid that error. However, maybe you can use a workaround and have the script rebuild the mailboxes automatically when such an error occurs. Try the following code:
    tell application "Mail"
      try
        set OldStuff to every message of mailbox TheBox where date received of it < OldDate
      on error
        activate
        tell application "System Events" to click menu item "Rebuild" of menu 1 of menu bar item "Mailbox" of menu bar 1 of process "Mail"
        delay 1 -- adjust if necessary
        set OldStuff to every message of mailbox TheBox where date received of it < OldDate
      end try
      repeat with ThisMessage in OldStuff
        delete ThisMessage
      end repeat
    end tell
    Since the above script uses GUI Scripting, you must enable the Accessibility Frameworks by clicking the checkbox labeled "Enable access for assistive devices" in the Universal Access System Preference pane.
    Message was edited by: Pierre L.

  • Applescript and mail rules:

    I'm trying to do something with rules that I can't easily do in preferences.
    I want to create a rule that does does the following:
    If from equals [email protected] OR  [email protected]
    AND
    message contains  "lawn"  or "Lawn" or "LAWN" or "XYZ" or "xyz" or "ABC"
    move message to mailbox M
    Or, do I just have to create a ton of rules?
    Also, assuming the answer to the above is true, I guess I could write a single apple script that did all my mail processing.
    I've searched and searched for such a script. Can anyone point me to something?
    I'm an applescript beginer.  I just ordered a book, but not here until next week.
    Thanks!
    Dave

    do it this way with an applescript (attach this to a rule action that checks all messages - will probably need some tweaking):
    set senderList to {"[email protected]", "[email protected]"}
    set keywordList to {"lawn", "Lawn", "LAWN", "XYZ", "xyz", "ABC"}
    using terms from application "Mail"
              on perform mail action with messages theMessages for rule theRule
                        tell application "Mail"
                                  repeat with thisMessage in theMessages
                                            if sender of thisMessage is in senderList then
                                                      repeat with thisKey in keywordList
                                                                if thisKey is in content of thisMessage then
                                                                          move thisMessage to mailbox "M"
                                                                end if
                                                      end repeat
                                            end if
                                  end repeat
                        end tell
              end perform mail action with messages
    end using terms from

  • Writing an AppleScript for Mail

    I have never written an AppleScript before, so I don't know if this is even possible. But, here goes...
    I manually process my junk mail by opening each message, clicking on "Long Headers," and forwarding to [email protected] Is it possible to write a script that would allow this process to be automated?
    Thanks.

    You can get the header text with this Applescript:
    Click here to launch Script Editor.
    tell application "Mail"
    the selection
    properties of item 1 of the result
    set thisHeader to all headers of the result
    end tell
    There is a sample Applescript included with Mail.app called "Create New Message.scpt", it should contain snippets to get you going.
    Or Google and there will be plenty of simpler ones. Truth be told, the Apple sample scripts are about the worst for learning from.

  • Applescript for mail to speak 'sent to'

    Hey, I use 6 mail accounts in mac mail, 4 of which are work addresses. I get a lot of mail to my 2 personal addresses which is low priority but i would like to setup speech to say the 'sent to' address when mail arrives. my computer screen is on sleep a lot of the time so if a mail arrives to a high-priority work address I would wake my screen to read immediately. Does anyone know of a script that would speak the mailbox/sent to name? thanks guys, dren.

    --- Code starts here ---
    using terms from application "Mail"
    on perform mail action with messages tMessages
    tell application "Mail"
    repeat with tMessage in tMessages
    say "Sent to " & (name of account of mailbox of tMessage)
    end repeat
    end tell
    end perform mail action with messages
    end using terms from
    --- Code ends here ---
    In 'Mail' 'Preferences' -
    01. Create a new rule.
    02. Leave the first popup button set to 'any', and select 'Every Message' from second popup button.
    03. Under 'Perform the following actions:', select 'Run AppleScript' from the only popup button.
    04. Click on the respective popup button's 'Choose...' button and navigate to where the above code is saved (as an AppleScript script file).

  • Applescript for mail.app won't send attachment

    I have an applescript to send a mail attachment but the mail sends without the attachment? Anyone know why?
    set theContent to (current date) as string
    set theSubject to "excel file"
    set theTarget to "someone @someplace.com"
    set theSender to "admin"
    set theName to "some name"
    set theAttachment to "mcp0_HD:Users:bill:Site:logs:deviceLogs.xls"
    tell application "Mail"
    set newMessage to make new outgoing message with properties {subject:theSubject, content:theContent & return & return}
    tell newMessage
    make new to recipient at end of to recipients with properties {visible:true, name:theName, address:theTarget}
    set sender to theSender
    tell content
    make new attachment with properties {file name:theAttachment} at after the last paragraph
    send newMessage
    end tell
    end tell
    end tell

    If you are still having problems, then there is something wrong with your file that you are trying to attach, or your declaration of this variable:
    set theAttachment to "mcp0_HD:Users:bill:Site:logs:deviceLogs.xls"
    Examine that very carefully. It is also a good idea to use the *path to* nomenclature (see the Dictionary for *+Standard Additions+* for more details) to access a file in cases like these. For example, here is the pertinent portion of a script that I have used since the Panther days to do precisely what you are trying to do:
    set pay_Path to ((path to documents folder as text) & "Cathouse:Payroll:Paysheets:Today.xls")
    tell application "Mail"
    set b to make new outgoing message with properties {sender:"[email protected]", subject:("Payroll")}
    set content of b to "Hello:
    Here is the payroll ending today: " & return & return
    tell b's content
    make new attachment with properties {file name:pay_Path as alias} at after the last paragraph
    end tell
    tell b to make new to recipient with properties {address:"[email protected]"}
    send b
    end tell
    I use this every other week to report my payroll to my accountant. It has never failed, and I am using Leopard (10.5.7).
    Good luck,

  • AppleScript for Mail

    Is it possible to make an applescript that will check for unread messages through the whole mailbox, then tell me how many there are, then say who each unread mail is from. Ask me to have it read the subject then open, mark as read, or leave for later?

    just like to add in my script based on the above
    i've been looking for something similar to this for a while and tried allsorts of snipets from many of the posts so heres my attempt
    this actually uses the mailbox or folder that is selected in mail.app so you dont have to explicitly tell it which folder you want to use (had that part of the code from another post somewhere so credit to them not me
    display alert "Please note!" message "This script may take a while if you have a lot of mailboxes selected. Do you want to continue?" buttons {"Cancel", "Yes"} cancel button "Cancel"
    tell application "Mail"
              tell front message viewer
                        set theSelectedMailboxes to selected mailboxes
                        repeat with a from 1 to length of theSelectedMailboxes
                                  set theCurrentMailbox to item a of theSelectedMailboxes
      processMailbox(theCurrentMailbox) of me
                        end repeat
              end tell
    end tell
    on processMailbox(theMailbox)
              tell application "Mail"
                        set unread_messages to (messages of theMailbox whose read status is false)
                        set unread_count to count unread_messages
      --display dialog "Total unread messages: " & unread_count
                        repeat with each_message in unread_messages
                                  set the_subject to subject of each_message
                                  set the_sender to sender of each_message
                                  set the_action to choose from list {"Open", "Mark as read", "Keep for later", "Delete"} default items {} with prompt "Subject: " & the_subject & return & return & "Sender: " & the_sender & return & return & "What do you want to do with this message?" & return with title "Unread message" without multiple selections allowed
                                  if the_action is false then return
                                  if item 1 of the_action is "Open" then open each_message
                                  if item 1 of the_action is "Mark as read" then set read status of each_message to true
                                  if item 1 of the_action is "Delete" then
                                            set read status of each_message to true
                                            set junk mail status of each_message to true
                                  end if
                        end repeat
              end tell
              tell application "AppleScript Editor"
      activate
                        display dialog "Do you want to delete the email?" buttons {"yes", "no"} default button 2
                        if result = {button returned:"yes"} then
                                  tell application "Mail"
      # deletes every message that is Read and marked as Junk.
      # Any that are not read AND junk will remain.
                                            delete (every message of theMailbox whose junk mail status is true and read status is true)
                                  end tell
                        else
                                  if result = {button returned:"no"} then
                                  end if
                        end if
              end tell
    end processMailbox

Maybe you are looking for