I want to write a simple script that is called by a Apple Mail Rule that delects the current email has an attachment of .ics type.
Here is what I have so far:
property theAttachmentPath : (path to "desk") as string
on run
tell application "Mail"
set theSelection to selection
activate -- make sure Mail is frontmost app after running the script...
end tell
end run
on perform_mail_action(info)
tell application "Mail"
set selectedMessages to |SelectedMessages| of info
- need code here to open mime-attachment.ics attachment
end tell
end perform_mail_action
Need help with the line that would tell Mail to open the attachment named “mime-attachment.ics”
unfortunately you can’t open attachments directly in Mail.app with AppleScript (AFAIK you can’t)
so you have to save it and open it from this location.
You can attach this script to a defined rule in Mail.app
property theAttachmentPath : (path to "desk") as string
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
repeat with This_Message in theMessages
tell application "Mail"
repeat with ma in mail attachments of This_Message
set n to name of ma
if n ends with ".ics" then
save ma in (theAttachmentPath & n)
tell application "Finder" to open (theAttachmentPath & n) -- or application "iCal"
end if
end repeat
end tell
end repeat
end perform mail action with messages
end using terms from
Okay, the reason I ask is I have created the suggested script above and attached it to a Mail Rule that checks for attachments that contain “.ics” and I have selected messages that contain .ics attachments and applied the rule and nothing happens.
with a little modification this script works on my machine:
property theAttachmentPath : (path to desktop) as Unicode text
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with This_Message in theMessages
repeat with ma in mail attachments of This_Message
set n to name of ma
if n ends with ".ics" then
save ma in (theAttachmentPath & n)
tell application "Finder" to open (theAttachmentPath & n) -- or application "iCal"
end if
end repeat
end repeat
end tell
end perform mail action with messages
end using terms from
This script worked great. Thank to every one involved. Can’t wait for Snow Leopard though, it will be sweet that it syncs with exchange right out of the box. But this will do for now. Thank you again.