applescript to save email-attachments in a folder doesn't work in Yosemite - operating-system

I've installed OS x 10.10.1
Now this script doesn't work:
tell application "Mail"
set theSelectedMessages to selection
set this_message to item 1 of the theSelectedMessages
tell this_message
set these_attachments to every mail attachment
repeat with z from 1 to the count of these_attachments
set this_attachment to item z of these_attachments
set this_name to the name of this_attachment as text
.........and so on
I get the message : error in the apple event Routine. The error comes in this line: "set these_attachments to every mail attachment"
In 10.9 the script worked.
WoWo
woide#wwp-service.de

G'day from the land of Oz
Your code, slightly modified, works. I think your use of 'selection' might be faulty, but haven't test it. Try 'selected mailbox'.
Regards
Brian Christmas
tell application "Mail"
set theSelectedMessages to messages of mailbox "* items to shift"
set this_message to item 1 of the theSelectedMessages
tell this_message
set these_attachments to every mail attachment
set AttachmentNames to {}
repeat with z from 1 to the count of these_attachments
set this_attachment to item z of these_attachments
set this_name to the name of this_attachment as rich text
set end of AttachmentNames to this_name as rich text
end repeat
end tell
end tell
AttachmentNames & return & z
--> {"2014-11-10 233839Z.zip", "2014-11-10 233839Z.zip", "(20141110233839Z 2).pdf", "2014-11-10 233839Z", "
", 4}

Related

Applescript to rule "sent mailbox zero"?

According to GTD and "inbox zero" I also wanted a corresponding "sent mailbox zero" by applying a rule in Apple Mail. (Why? Please, see the end of this question.)
Now, here is a simple Applescript solution: sortOut. How could it be more efficient?
The workflow is simply this
Loop through all sent messages that was a reply to some other message.
Get the message id of the message the sent message was a reply to.
Locate the mailbox for this (prior) message.
Any suggestions how to solve step 3 more efficiently will be appreciated, e.g. locating a mailbox directly based on message id, without having to use the message: protocol and then open the message and preferably not to code something like ... (in every mailbox) whose message id is mID which turns out to be rather slow.
tell application "Mail"
set i to 0
set mb1 to sent mailbox
repeat with m in ((messages of mb1) whose all headers contains "In-Reply-To")
set mID to content of header "In-Reply-To" of m
set cmd to "open 'message:" & mID & "'"
try
do shell script cmd
delay 1
set s to the selection
set m2 to item 1 of s
set mb2 to mailbox of m2
set mailbox of m to mb2
close front window
set i to i + 1
end try
end repeat
if i ≠ 1 then
set s to "s"
else
set s to ""
end if
set myMsg to (i & " message" & s & " moved successfully") as rich text
display notification myMsg with title "SortOut" subtitle "Sorting complete"
end tell
Some earlier discussions elsewhere indicate that some people may even wonder why I want this. My reason is simply that I like to have have all threads and conversations, concerning every project and deadline, collected together based on context.
When a project is finished I archive it as a completed entity for easy reference if I need to go back or follow up some things (e.g. when planning a yearly event, “Remember what I replied to this question last year?” That also means that all those conversations will have the same label in gmail.
So, instead of having almost 15000 sent emails in one mailbox, I now have them sorted into context based mailboxes—and the mailbox for sent messages is empty!
BTW, the Alfred workflow Mail Actions by Pedro Lobo is simply amazing for filing mail. My script sortOut does the rest ;-)
Sorry, Pedro, I didn't have enough reputation to post a link to your brilliant work.
I just updated the code but still could not locate the mailbox corresponding to a message id from the In-Reply-To header using Applescript (without the message:protocol).
tell application "Mail"
set i to 0
set mb1 to sent mailbox
repeat with m in ((messages of mb1) whose all headers contains "In-Reply-To")
set mID to content of header "In-Reply-To" of m
set cmd to "open 'message:" & mID & "'"
try
do shell script cmd
delay 1
set s to the selection
set m2 to last item of s
set mb2 to mailbox of m2
if name of mb2 does not contain "INBOX" then
set mailbox of m to mb2
close front window
set i to i + 1
end if
end try
end repeat
if i ≠ 1 then
set s to "s"
else
set s to ""
end if
set myMsg to (i & " message" & s & " moved successfully") as rich text
display notification myMsg with title "SortOut" subtitle "Sorting complete"
mb2
end tell

Applescript mail flagging not working in maverick?

I am working on applescript and the following does not work :
I've put the file in the script folder, created a rule which find messages but the script does never happen.
I tried to flag, change the background color to no avail. The rule "test" exists.
What is wrong here?
Code :
using terms from application "Mail"
-- on perform mail action with messages selectedMessages
set today to current date
set deleteDate to today - (7 * days)
on perform mail action with messages selectedMessages for rule test
tell application "Mail"
repeat with eachMessage in selectedMessages
-- repeat with a from 1 to 5
--- Process the current message
-- set background color of eachMessage to white
-- if date received of eachMessage in selectedMessages is after deleteDate then
set background color of eachMessage to white
set flagged status to false
-- end if
-- display dialog theText
end repeat
end tell
end perform mail action with messages
end using terms from

AppleScript and Mail.app: checking if new messages contain a string

I'm writing a script to check if a particular web form has been submitted.
The script so far reads thusly:
tell application "Mail"
check for new mail
set newmail to get the unread count of inbox
repeat with msg in newmail
if msg's subject contains "New newsletter built by" then
return msg's subject
end if
end repeat
end tell
I've got an unread email in my inbox for the script to work with, but I still get an error:
error "Mail got an error: Can’t make 1 into type specifier." number -1700 from 1 to specifier
Any help at all will be appreciated.
Cheers!
tell application "Mail"
check for new mail
repeat until (background activity count) = 0
delay 0.5 --wait until all new messages are in the box
end repeat
try
return subject of (first message of inbox whose read status is false and subject contains "New newsletter built by ")
end try
end tell
Applescript is a bit tricky. It looks like you're trying to parse the count of the inbox, not the actual inbox.
Try this script instead:
tell application "Mail"
check for new mail
-- instead of getting the unread count of inbox
-- let's set an Applescript variable to every message of the inbox
set myInbox to every message of inbox
repeat with msg in myInbox
-- and look at only the ones that are unread
if read status of msg is false then
-- and if the subject of the unread message is what we want
if msg's subject contains "New newsletter built by" then
-- return it
return msg's subject
end if
end if
end repeat
end tell
I've actually solved the issue, so I'm going to post it here should anyone else need help. Check it:
tell application "Mail"
check for new mail
set checker to (messages of inbox whose read status is false)
set neworder to number of items in checker
if neworder > 0 then
repeat with i from 1 to number of items in checker
set msg to item i of checker
if msg's subject contains "New newsletter built by " then
return msg's subject
end if
end repeat
end if
end tell
adding to what jackjr300 said....
tell application "Mail"
set x to unread count of inbox
check for new mail
delay 3
set y to unread count of inbox
set z to y - x
end tell
if x = y then
say "There is nothing to report"
end if
if z = 1 then
say "You have one new message"
end if
if z = 2 then
say "You have two new messages"
end if
if z = 3 then
say "You have three new messages"
end if
if z = 4 then
say "You have four new messages"
end if
if z = 5 then
say "You have five new messages"
end if
if z = 6 then
say "You have six new messages"
end if
if z = 7 then
say "You have seven new messages"
end if
if z = 8 then
say "You have eight new messages"
end if
if z = 9 then
say "You have nine new messages"
end if
if z = 10 then
say "You have ten new messages"
else
say "You have more than ten new messages"
end if

How can i modify this applescript to apply to selected emails rather than selected mailboxes?

tho is my first post - glad to have found this community :)
I'm afraid I have limited applescript knowledge but I discovered a script that will create a new message with recipients based on senders of emails in a particular mailbox.
This is almost what I need...
What I really need is a script that will create a new message with recipients based on senders of all selected emails.
I am actually astonished that this is not an option in more mail clients. It's not an option in Mail, nor Mailmate, nor Entourage.
The code I am working with is...
tell application "Mail"
set theSenderList to {}
set theMailboxes to the selected mailboxes of message viewer 0
repeat with aMailbox in theMailboxes
repeat with aMessage in messages of aMailbox
set end of theSenderList to sender of aMessage
end repeat
end repeat
set newMessage to make new outgoing message with properties {visible:true, subject:"Answers to ", content:"Here is the solution to "}
repeat with aSender in theSenderList
tell newMessage
make new bcc recipient at end of bcc recipients with properties {address:aSender}
end tell
end repeat
end tell
To access the selected messages, you can simply use selected messages instead of selected mailboxes. Once you've made this change, the loop over the selected mailboxes no longer applies. Instead, keep just the inner loop over messages.
...
set theMessages to the selected messages of message viewer 0
repeat with aMessage in theMessages
set end of theSenderList to sender of aMessage
end repeat
...
To find this sort of thing yourself:
open the AppleScript editor,
open the library window (Window → Library, or ⇧⌘L)
add the application to the library (click the plus symbol in the library window),
open the scripting dictionary for the application (double click the application in the library window)
Select the Mail suite, then the message viewer class in the browser.
You can also open a scripting dictionary via File → Open Dictionary..., or with ⇧⌘O.
In the properties for the message viewer, you'll see both "selected messages" and "selected mailbox".
The dictionary viewer uses a number of icons in the browser to indicate the type for a term
Suite: an "S" in an orange square.
Class: a "C" in a purple square.
Command: a "C" in a blue circle.
Element: an "E" in an orange square.
Property: a "P" in a purple square.
See Also
Where to find what commands/properties are available for AppleScript in Microsoft Outlook 2011?

Mail "Can't continue" for a AppleScript function

I'm trying to write an AppleScript for use with Mail (on Snow Leopard) to save image attachments of messages to a folder. The main part of the AppleScript is:
property ImageExtensionList : {"jpg", "jpeg"}
property PicturesFolder : path to pictures folder as text
property SaveFolderName : "Fetched"
property SaveFolder : PicturesFolder & SaveFolderName
tell application "Mail"
set theMessages to the selection
repeat with theMessage in theMessages
repeat with theAttachment in every mail attachment of theMessage
set attachmentFileName to theAttachment's name
if isImageFileName(attachmentFileName) then
set attachmentPathName to SaveFolder & attachmentFileName
save theAttachment in getNonexistantFile(attachmentPathName)
end if
end repeat
end repeat
end tell
on isImageFileName(theFileName)
set dot to offset of "." in theFileName
if dot > 0 then
set theExtension to text (dot + 1) thru -1 of theFileName
return theExtension is in ImageExtensionList
end if
return false
end isImageFileName
When run, I get the error:
error "Mail got an error: Can’t continue isImageFileName." number -1708
where error -1708 is:
Event wasnt handled by an Apple event handler.
However, if I copy/paste the isImageFileName() into another script like:
property ImageExtensionList : {"jpg", "jpeg"}
on isImageFileName(theFileName)
set dot to offset of "." in theFileName
if dot > 0 then
set theExtension to text (dot + 1) thru -1 of theFileName
return theExtension is in ImageExtensionList
end if
return false
end isImageFileName
if isImageFileName("foo.jpg") then
return true
else
return false
end if
it works fine. Why does Mail complain about this?
It may be a quirk, but it has an explanation. If you're in a tell application "whatever" block, all calls are made in the namespace of that application's dictionary, not your script's dictionary. Because of that, you have to explicity tell AppleScript to look back into your script for the name. Saying my is like saying tell me, instructing the script where to look for the function.
Try "my isImageFileName". It's not Mail, just a quirk of AppleScript.