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)
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" 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. -
Packagemaker: need to run applescript from postflight script
Does anybody makes packages using Packagemaker? I need to run applescript from postflight shell script. Generally, when we need to run applescript or any application from shell script we write:
#!/bin/sh
open /Path/to/applscrpt.app
But what to do if all scripts (shell, app's) placed in MyPackage.pkg/Contents/Resources? What path I need to specify? This way:
#!/bin/sh
open ./Contents/Resources/applscrpt.app
doesn't work...The $1 argument that gets passed to your postflight script by the Installer should contain the full path to the package that's currently being installed. So something like this should work...
#!/bin/sh
open "$1/Contents/Resources/applscrpt.app"
Here is some additional info about args and environment variables available to your scripts.
Steve -
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. -
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: 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 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 -
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 -
Running Maxl from business rule
Hi,
We have very large BSO cube and we decided to create ASO for aggregation purposes.
We were thinking of running the replicate partition with Maxl, but we want to do it at the end of every business rule.
In order to do it we want to have the possibility to run Maxl from the BR. We heard that there is a way to do so, but we couldn't find guide / tutorial / any other thing that will give the proper explanation.
We are working with 11.1.2.2
Can someone help?
Thanks,
Ramiduplicate post https://forums.oracle.com/message/11106737
-
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 -
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 fromsorry 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. -
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). -
Mail Rules don't work in Mavericks
It seems with the update to 10.9 Mavericks Mail rules no longer work. My email address was harvested by spamers and I have been using rules to weed throught the 100's of emails that I receive each day.
Russian Brides, Vigra, Learn a new language get moved into the trash when delievered. Now nothing happens.
I just tried to write a new rule and when I clicked the Prefs pannel I got the spinning cursor. After waiting for some time I did a force quit only to find that Mail was not responding.
Anyone have any ideas? I did not see any major changes with Mail and Mavericks so I'm not sure why it's been effected.
MDYou might condider using an Applescript with Mail Rules.
Here's one that I use (Use whitelist to not move to spam):
(Just edit to your junk or whitelist)
Note: The Applescripit must be saved to: ~/Library/Application Scripts/com.apple.mail/
The rule:
The AppleScript:
using terms from application "Mail"
on perform mail action with messages theMessages
tell application "Mail"
repeat with theMessage in theMessages
set theSender to (sender of theMessage)
set theReplyto to (reply to of theMessage)
set theSubject to (subject of theMessage)
set theHeader to (all headers of theMessage)
set theContent to (source of theMessage as string)
set theAccount to (account of mailbox of theMessage)
if my blacklist(theSender, theReplyto, theSubject, theHeader, theContent) ¬
and not my whitelist(theSender, theHeader) then
my moveToJunkFolder(theMessage, theAccount)
end if
end repeat
end tell
end perform mail action with messages
end using terms from
on blacklist(f, r, s, h, c)
if h contains "X-YahooFilteredBulk" or ¬
h contains "Received-SPF: fail" or ¬
h contains "Received-SPF: softfail" or ¬
h contains "Received-SPF: error" or ¬
h contains "Received-SPF: permerror" or ¬
h contains "Received-SPF: temperror" or ¬
h contains "streamsendbouncer@" or ¬
s contains "[Bulk]" or ¬
f contains "Vigra.candianmeds.com" or ¬
f contains "[email protected]" or ¬
f contains ".cz" or ¬
r contains ".ma" then
return true
end if
end blacklist
on whitelist(f, h)
if f contains "aicpa" or ¬
f contains "eWeek.com" or ¬
h contains "from macbook-air.local" then
return true
else
return false
end if
end whitelist
on moveToJunkFolder(m, a)
tell application "Mail"
try
set the read status of m to true
set the junk mail status of m to true
set theAccount to (account of mailbox of m)
set mailbox of m to (mailbox "Junk" of a) -- Move to "Junk"
end try
end tell
end moveToJunkFolder -
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 -
Mail Rules window says "No Scripts Installed" next to "Run AppleScript"
I'm trying to create a rule in Mail that will run an AppleScript. But when I choose "Run AppleScript" in the action section of the rule-creation window, the dropdown to the right says "No Scripts Installed".
If I click on that dropdown, it has one option: "Open in Finder". When I choose that, a Finder window opens to the folder Library/Application Scripts/com.apple.mail/. I dropped my AppleScript file into that folder, but when I tried again to make a rule, I still got the "No Scripts Installed" dropdown.
I'm running Mail version 6.3 in OS X 10.8.3.
Any idea how to get this working properly? Thanks.When Finder opens the directory for your AppleScript (in the case of OS 10.9.1, "Library>Application Scripts>com.apple.mail"), make sure your script (not a shortcut to your script) is copied there. Once it is, you will see the script in the dropdown menu where you initially saw "No Scripts Installed".
Hope this helps.
Maybe you are looking for
-
Windows Vista C++ error on startup
I recently updated iTunes and quicktime using the Apple update manager, but when I switched off my laptop and restarted again i got a message which said there was a microsoft visual c++ runtime library error and wouldn't let me boot up. I had to star
-
I recently changed my Apple ID but I keep getting messages from my Cloud account asking for my password to my old Apple ID. If I go in and delete the current Cloud account that appears to still be associated with my old ID and set up new one with my
-
AIR error message while previewing
Hi, I am using Captivate 5, running on Windows 7 (32-bit) OS, with 4 Gigs RAM. When previewing a Captivate moview, by pressing F4 key, Captivate throws an error in a pop-up window, titled "Adobe AIR". The message reads: This installation of this appl
-
Hi guys, A quick newbie question : How do I go about creating servlets in Workshop? and/or, I alternately copy a servlet file in my classes folder and manually tweak the web.xml file to point to this class in a WebProject. I however have to do the co
-
[SOLVED] Problems with systemd's journal when using syslog() in C
Hi, I have a problem with journalctl and syslog output within a C program: When I use journalctl in follow mode: $ journalctl -f and I run the folowing program in another terminal #include <stdio.h> #include <syslog.h> int main() FILE *pf; int i; /