Is there an AppleScript to read Message's message content - applescript

I am trying to have a script that can read messages (sent from me & 1 other person) and then I am going to have python pull the content into a python script. I have not dealt with applescripts much so any help will be appreciated.

Related

Windows SendTo from script

I'm writing an application where I have to send an email with an attachment using the default mail application.
Before the email is sent, I want the user to be able to edit the text, i.e. the application should just open the mail client with pre-filled recipient and attachment and give the user the opportunity to send it.
At very minimum I need the same effect I'd got if I selected "SendTo/Mail Recipient" from the context menu of the file.
Solutions based on the "mailto:" trick won't work as there are mail clients that do not support the "attachment=" part.
The most complete solution I've found is this one:
http://www.codeproject.com/Articles/3839/SendTo-mail-recipient
but it seems a lot of code for something so simple! (and also crashes when compiled with VS2008)
Is there any other option? It would be ok even if it was an external tool or script (e.g. a .vbs script to be launched with cscript).
I would advise you to use MAPI (Messaging Application Program Interface).
If dotNet can be part of the solution, here's a ready-to-use class in C# : Class for creating MAPI Mail Messages. It would give you something like this:
MapiMailMessage message = new MapiMailMessage("Test Message", "Test Body");
message.Recipients.Add("Test#Test.com");
message.Files.Add(#"C:\del.txt");
message.ShowDialog();
Otherwise, you can always do it in C++ if you feel confortable with it, like this answer suggest.
Then, you will be able to ShellExecute the binary executable and pass it some parameters.
Hope this helps :-)

Simple AppleScript to export Apple Mail messages to FileMaker DB?

I'm using a product called "Mail Archiver X" to archive messages from Apple Mail into a custom FileMaker database ("eMailViewerX" - this is the target database that comes with Mail Archiver and is required for the process), from where I copy these messages to my main message archive (another FileMaker DB).
While that process works, it is kind of clumsy (Apple Mail > Mail Archiver X > FileMaker DB #1 > FileMaker DB #2) - and it breaks every time when there is a new version of Apple Mail or OS X until "Mail Archiver X" has been updated by the developer.
So I'm looking for a more simple solution: an AppleScript that will export all messages from exactly one folder ("To Archive") in Apple Mail (4.5/Snow Leopard or 5.0/Lion) as a simple CSV or .tab file, with the following data per line:
Message Sender*
Message Receiver*
Sent Date
Sent Time
Subject
Body
(* Separation of name and e-mail address would be cool, but I understand this may not (always) be possible.)
The only tricky part may be the conversion of carriage returns in the e-mail messages' body into the special character FileMaker expects in TAB or CSV files. In BBEdit, this is shown as \x{0B} (UTF8: 0B). So there would have to be a Find/Replace for that in the script.
No interface, no configuration - just something that spits out all messages from a folder and tells me when it's done.
This does not have to be free (although I wouldn't mind :) - I'd gladly pay for something reliable and simple.
If someone knows about such a script or is willing to write it, I would really appreciate it. I haven't found anything.
TL;DR: I need to export all messages from an Apple Mail folder to a FileMaker-readable CSV file.
There is software called Mail to Filemaker Importer, it's less than $20.
Is this an IMAP mailbox? If so you could use a plugin and download the messages directly into FileMaker records.

Automatically adding attachments to all outgoing mail messages

A two-part newbie question, guys... I've only just discovered AppleScript and I'm hoping to automagically attach a 'pdf' file to every outgoing (sent) "Mail.app" message.
(Q1) I've got it working successfully in tests running direct from Script Editor - with the file located in the Documents folder - and I'm using:
set pdfFile_Path to ((path to documents folder as text) & "paginatedPDF.pdf")
but the filepath bit confuses me... How would I change this line if I wanted to store my file inside a folder called "PDF's to send" on my desktop?
(Q2) How can I attach the script as a Mail.app rule (the rule options only seem to offer incoming mail message conditions, not outgoing ones)?
Any help/advice much appreciated. Thanks :-)
Have you tried dragging and dropping the PDF straight into your Signature?

Automator / AppleScript to process incoming emails in Mac Mail

I'm designing an app that allows users to email me crash reports if my app ever crashes. I'd like to leave Mac Mail running on a computer and when an email comes through, an automator script / AppleScript runs to process the contents of the body of the email.
I've got the entire parsing/processing done in a python script, except I have to manually copy the contents of the email into a file and then run my parser on that file.
What's the best way to set this up so I can the contents of the email be pushed into my parsing script?
Many thanks!
Probably the simplest approach is to define a Mail.app Rule. You can set up filtering conditions to specify the set of incoming email to apply the rule to and among the rule actions you can specify is one to run an AppleScript on incoming messages. Rules are managed with Mail.app Preferences -> Rules. Apple supplies examples of Rule Action scripts with Mac OS X. Look in /Library/Scripts/Mail Scripts/Rule Actions or search the web.
Here's a script that extracts from email into a file using a mail rule: MacScripter / Mail rule script for message export. Might be good for sample code for what you're doing.
Use the Dictionary in Applescript Editor to see the properties of mail and you'll quickly be able to see the properties of any mail message. Here's a quick and dirty example of getting the content of a mail message.
tell application "Mail"
set the_messages to selection
repeat with this_message in the_messages
set mytext to content of this_message
end repeat
end tell
Modify the script linked to above that copies output to a temporary file and then pass that file to your Python script to act on.

What's wrong with this Applescript?

My app has some rudimentary applescriptability. There is one method (receivedInstantMessage) that takes a single parameter (message) and passes it to my app which then processes it.
The following applescript:
tell application "MyApp"
receivedInstantMessage "This is a message"
end tell
Works perfectly. My app presents a dialog containing the message ("This is a message").
I'm trying to set it up so that when I send an IM to iChat, it runs an applescript that will send the contents of the message to my app. I have told iChat to run a script when a message is received and I know that part is working. The script I am now using does not work:
using terms from application "iChat"
on message received theMessage from theBuddy for theChat
tell application "MyApp"
receivedInstantMessage theMessage
end tell
end message received
end using terms from
Nothing happens when I receive a message. Even if I substitute the message variable (theMessage) from iChat and use an arbitrary string it still does nothing.
What am I doing wrong. I'm quite new to applescript (being a REALbasic coder normally).
[Update]: This seems to work now. A simple restart of the Mac fixed things. Very odd...
just a semantic detail: Consider the scripter is sending messages to your app, not receiving them. Yes, your app is receiving them, but the terminology you chose "receivedInstantMessage" is from the point of view of your app, not the scripter.
Additionally, it is considered naff to have terminology in camel case. AppleScript terminology can (and often should) contain spaces. And if you really want to do it properly you should separate the terminology into nouns and verbs. (Where nouns are properly-modelled objects, with properties, and verbs are commands for manipulating them. In this case you probably want something like send message "bla", where a message is an object with properties like sender, recipient, channel etc. and send is a command which takes a message object as a parameter - check the dictionary of Snak for a quite nice - but not perfect - implementation).
Sorry if this sounds anal. I have been applescripting for many years, and while I really appreciate it when developers add applescript support, I know I speak for all applescripters when I say that poorly constructed dictionaries, and poor terminology choices are frustrating and irritating, especially as the app gets more mature and the developer starts to say things like "I know the applescript interface needs a complete overhaul but I don't want to break existing scripts!". ALL applescripters prefer it if the scripting interface gets better, even if it breaks existing scripts. So: Do it wrong now, but be prepared to fundamentally improve it later. :)
Even Apple has some lousy terminology, for example in iTunes there is an updatePodcast and updateAllPodcasts command. This is just wrong, according to their own technote 2106 - pay particular attention to the section on naming rules.. They should have a podcast object and an update command, so that you could also do things like "delete every podcast whose name contains "Ann Coulter". ("Whose" clauses are one of the coolest features of appleScript!)

Resources