Applescript to activate a Mail rule
Hi I have set up an out of office rule for someone in our studio but it needs to be activated and deactivated every Monday. I have CronniX which can handle the activation of the script but i'm banging me head trying to find a script that activates a Mail rule they all seem to be the other way round. (rule activating the script)
Any help is appreciated.
Thanks
This is exactly what I need as well, could you share the link. I've registered for MacScripters now, but I haven't received my password, so I can't seem to search.
Similar Messages
-
Why is the applescript action in a mail rule always pushed last?
Hi,
I try to create a rule in Mail such that an Applescript is executed and then other things are done to the message (such as move it to a folder, for example). I want this to be the preceise order of things: first, do script, next, do other things.
I create my rule in the Mail preferences, and it all goes fine. But when I reopne the rule to examine it again, I see that the Applescript part of the actions has now been pushed to the end of the action list.
I wonder if anyone can explain the logic of this? I didn't find any reference in the help for why is this happening. Is it because of the possible time-out associated with the applescript (so as not to hang the rest of the rule evaluation)?
Thanks for any insights.
-- ivan
PM DC 2Ghz G5, PB 1.5GHz G4 Mac OS X (10.4.5)I don't know exactly but it might be that Mail has no way of knowing that the Applescript has completed in order to continue. So, making it the last step ensures that the complete rules will work everytime.
What are you trying to do with your messages? Perhaps we can figure out a workaround.
Bronson -
Please help with troubleshooting Applescript invoked by Apple Mail rule
I set up an account with Boxcar to get push notification of incoming email on my iPhone. I did this because I passworded my iPhone and cannot see incoming messages without entering the password. Now all I need to do is glance at the screen to see whether it's worth it or not to look at the email. In order to use the Boxcar service, I needed to set up a rule to redirect all incoming mail to my private address on Boxcar. The issues that I have are two-fold. First, I do not like blindly forwarding email content to Boxcar regardless of their stated claim that they strip out the sender and subject of a message and discard the rest. Second, if I get a large incoming email, then My method will have to send the large content out again - a waste of resources. To get around this, I tried to write an Applescript for Apple Mail that is invoked by a rule applicable to all messages. The script redirects all messages to my private Boxcar email address and strips out the content of the message. The script follows:
using terms from application "Mail"
on perform mail action with messages selectedMessages
set AppleScript's text item delimiters to ""
repeat with theMessage in selectedMessages
set boxcarMessage to redirect theMessage
tell boxcarMessage
make new to recipient at beginning of to recipients with properties {address:"[email protected]"}
set content to " "
set subject to theMessage's subject
end tell
send boxcarMessage
end repeat
end perform mail action with messages
end using terms from
The problem with this script is that it still sends out the content even though I thought I was setting it to a single space. Other than that, it does just what I need it to do. Any suggestions on corrections, an easier Applescript, or another way to approach the whole issue? One drawback to this approach is that I need to have a Mac running at home that processes the rule for the incoming messages - probably there is no way around this?
Thanks!That makes sense, but then that gets back to your original comment:
"redirecting the message will send the entire message, as-is."
I tried to eliminate the attachments by adding the line:
delete boxcarMessage's attachments
but it did not work - the attachments were redirected also. So here is the script as it stands now:
using terms from application "Mail"
on perform mail action with messages selectedMessages
set AppleScript's text item delimiters to ""
repeat with theMessage in selectedMessages
set boxcarMessage to redirect theMessage
delete boxcarMessage's attachments
tell boxcarMessage
make new to recipient at beginning of to recipients with properties {address:"[email protected]"}
end tell
delay 3
send boxcarMessage
end repeat
end perform mail action with messages
end using terms from
I appreciate the input. Intuitively it seems like this is doable, but the solution escapes me. -
Applescript to trigger a Mail Rule
I'm trying to do something I thought would be simple ... but I can't figure it out.
My goal is to get specific messages from one mailbox and put them into my Inbox. I've used a rule with a MailTags deadline to get the messages into the box, and I have created a rule to move mail with a deadline of today or earlier back to the Inbox. I would like to automatically apply the "move to inbox" rule to the contents of the other mailbox, so I can have iCal move my messages every morning.
I am not very good at scripting, and I can't figure out how to write a script to apply the move to inbox rule to every message in the other mailbox. Can someone help me or point the way to a script that I can adapt? Everything I've found works the other way (using a rule to call a script — I want a script to call a rule).
Or, is there a better, easier way to do this? It is important that the process can be set to run automatically. This whole thing is to get messages that are "on hold" out of my inbox until the time when I can deal with them. If they don't come back automatically, I'll forget about them.
I did try using a SmartFolder — but creating a SmartFolder that works off MailTags rules makes my system slow to a crawl, and the badge counts are all off.
Thanks in advanceI'm trying to do something I thought would be simple ... but I can't figure it out.
My goal is to get specific messages from one mailbox and put them into my Inbox. I've used a rule with a MailTags deadline to get the messages into the box, and I have created a rule to move mail with a deadline of today or earlier back to the Inbox. I would like to automatically apply the "move to inbox" rule to the contents of the other mailbox, so I can have iCal move my messages every morning.
I am not very good at scripting, and I can't figure out how to write a script to apply the move to inbox rule to every message in the other mailbox. Can someone help me or point the way to a script that I can adapt? Everything I've found works the other way (using a rule to call a script — I want a script to call a rule).
Or, is there a better, easier way to do this? It is important that the process can be set to run automatically. This whole thing is to get messages that are "on hold" out of my inbox until the time when I can deal with them. If they don't come back automatically, I'll forget about them.
I did try using a SmartFolder — but creating a SmartFolder that works off MailTags rules makes my system slow to a crawl, and the badge counts are all off.
Thanks in advance -
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) -
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 -
Using a Mail rule to run an AppleScript
I've been trying to get a Mail rule to run a very simple AppleScript on 10.5.3 and it just doesn't work, period.
I've tried making everything as simple as possible:
1. My Mail rule sets the background color of a message and runs the AppleScript if the subject contains "test".
2. The AppleScript displays a Finder alert.
[(screenshot)|http://i26.tinypic.com/nqxou8.png]
Naturally, the script runs fine within the Script Editor. I also know that the rule works since the background color action gets applied.
But, the AppeScript never runs when I apply the rule to a message manually or when it gets automatically applied to new messages. I really can't imagine where I'm going wrong here...You can't simply feed it some arbitrary script to execute, you have to write a handler that Mail can dispatch events to. This generally looks something like
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with suspectMessage in theMessages
--do something
end repeat
end tell
end perform mail action with messages
end using terms from -
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!
Davedo 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 -
Applescript process message body from mail rule help please
Would someone be kind enough to help me figure out how to do this? I've been reading for hours on other posts and I can't get this to work.
Here is an example:
I would like to set up a mail rule to run an applescript that searches the body of the email for "-Front Door- Open". I then want to parse the body and sets myDevice= "-Front Door-" and myState="Open". After I have these variables set, I want to make an call to something like https://foo.me.com/api/token/${state.accessToken}/smartapps/installations/${app.id}/Notify?device=${myDevice}&type=ContactSensor&state=${myState}
I understand how to do the mail rule, I just can't figure out the applescript part of it.The script works just fine - at least, as designed if not as expected.
When the script runs, Mail and/or AppleScript looks for a perform mail action handler. If that is found, the commands within are executed.
If there is no perform mail action handler then the script is run as-is (i.e. as if you clicked 'Run' in AppleScript Editor).
And that's exactly what's happening here. In the first case (that works) the script is running because there's no (visible) perform mail action handler.
In the second case where it apparently doesn't work, there is a handler, so that handler is being executed. Any code outside that handler is ignored (unless it's called from within the perform mail action handler.
Since your 'say' command is outside the handler, it is ignored. However, if you move it inside the perform mail action handler you'll hear your speech. -
Applescript run from Mail rule does not run
I am attempting to run an Applescript from a Mail rule. Basically, the Applescript does not run.
Stripped to the bare essentials, the following script runs fine when Applying a rule in Mail:
say "Hello"
as well as this one:
say "Hello"
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
-- statements to process each message in theMessages
end tell
end perform mail action with messages
end using terms from
But, when I remove the comments from the block lifted verbatim from the Applescript manual:
say "Hello"
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
-- statements to process each message in theMessages
end tell
end perform mail action with messages
end using terms from
the script does not even say Hello.
I am trying to go as far as having the Applescript create a new ToDo based on specific incoming emails, but I can't get any but the simplest Applescript to run.
Can anyone help me?
TomThe script works just fine - at least, as designed if not as expected.
When the script runs, Mail and/or AppleScript looks for a perform mail action handler. If that is found, the commands within are executed.
If there is no perform mail action handler then the script is run as-is (i.e. as if you clicked 'Run' in AppleScript Editor).
And that's exactly what's happening here. In the first case (that works) the script is running because there's no (visible) perform mail action handler.
In the second case where it apparently doesn't work, there is a handler, so that handler is being executed. Any code outside that handler is ignored (unless it's called from within the perform mail action handler.
Since your 'say' command is outside the handler, it is ignored. However, if you move it inside the perform mail action handler you'll hear your speech. -
Can Applescript fix this problem with no Reply-To field in mail rules.
Hi I'm trying to sent up an automatic response email in mail rules, the problem is when I filter the email I want to respond to, I don't get the option to send a response to the "Reply-To" field, I can only reply to the "From" field which is no good to me. The mails I receive are booking inquiries generated by an online form so the "From" field is always the same email address not the guest address which is in the "Reply-To" field.
Can any applescript genius out there help me out, it would save me so much time !!
Thanks
JonGive this a shot. Change the text in the quotes in the property line to whatever you want for the body.
property theBody : "This is the autoreply message"
property theQuote : "You wrote:"
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with aMessage in theMessages
set theSubject to "Re: " & the subject of aMessage
set theReplyTo to reply to of aMessage
if theQuote is not "" then
set theBody to theBody & return & return & theQuote & return & return & the content of aMessage
end if
set theReply to make new outgoing message with properties {subject:theSubject, content:theBody}
tell theReply
make new to recipient with properties {address:theReplyTo}
end tell
send theReply
end repeat
end tell
end perform mail action with messages
end using terms from
If you set theQuote to "", then it won't quote the original. The quote is plain text, so not a great solution.
There is an option in Applescript to reply to a message, but it does the same as the rule. I tried to edit that message, but it didn't let me. So, I went with the above method.
You might try [the Applescript forum|http://discussions.apple.com/forum.jspa?forumID=724]. -
Mail rules have stopped executing applescripts
I have 3 mail rules that run different applescripts to process mail into other apps (omnifocus and yojimbo). Sometime in the last few days, these rules stopped processing the apple scripts. I know the issue is not the scripts themselves, because I can execute them manually just fine.
I'm not sure why they have stopped working, but there are two changes that have happened on my computer that I think might have created the issue:
1) I installed the Safari 4.0 beta
2) I began syncing mail rules with another machine. (This created duplicate rules, but I have deleted them.)
Anyone have any ideas what might be causing my issue?you can submit a bug report here:
https://bugreport.apple.com/cgi-bin/WebObjects/RadarWeb.woa/wa/signIn
You will need ADC membership to do so. it's free and you can use your existing apple id to get it. -
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" folderI 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. -
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 -
Mail Rule Applescript to Forward Email Attachments Only
Hi Everyone,
I'm running 10.8.4 and Mail 6.5. Using Mail Rules, I'd like to forward emails containing attachments but not the message content (contained in the email to be forwarded). I am not an AppleScriptor but have tried to write code...with no luck. Does anyone know of such a script that can be activated using Mail Rules? Or propose a script I could use?Hi Everyone,
I'm running 10.8.4 and Mail 6.5. Using Mail Rules, I'd like to forward emails containing attachments but not the message content (contained in the email to be forwarded). I am not an AppleScriptor but have tried to write code...with no luck. Does anyone know of such a script that can be activated using Mail Rules? Or propose a script I could use?
Maybe you are looking for
-
How to dump a excel file in the mysql db?
Hi, I just want to dump a excel file in the mysql db. Can you please tell, how it can be done? what steps should I taken for that? Please help me. Thanks
-
Help! Built in features/hints not working flash cs6. Need fix ASAP
Loads of built in features are not working for me in Flash CS6. When I was using CS4 they did, now they aren't. I will give two examples. Say for example I am writing code in the actions window and I type "green_btn." in regards to the name of a butt
-
Control key launches Mission Control
I have a new Macbook Pro (i7, Thunderbolt) that recently underwent upgrade to Lion. Since then Mission Control launches everytime the user hits the Control Key. We have set all keyboard shortcuts to default and it did not correct the issue. This is j
-
Get the font names and image names in QXD
Hi, How to get the font names and image name in Quarkxpress document file using java?. Is any third party packages for getting font n image names in QXD? thanks, nithya
-
What does the Traffic Setting under Location Services do in iOS 5?
What does the Traffic Setting under Location Services do in iOS 5? Do I loose anything valuable by turning that function off on my 4S?