The following is an applescript which is meant to take the body of the latest email and extract text out of it. As you can see the result is shown below. This result is show as the script was running correctly before. Now it is not.
The email I sent later on contained the message "#tech sxi" but the script is not showing the correct output for this email. This is not the only one. Every time, I am sending a new mail and running the script again, i get the same problem, the result just does not change.
Best Answer
As one of the commenters alluded to, "get first message of inbox" probably won't return what you expect.
When retrieving messages using AppleScript, Mail sorts your mailbox accounts alphabetically. Within each account's inbox, messages are sorted newest first. What you have selected in Mail doesn't change the order in which they're returned to AppleScript.
So if you have the following accounts and inbox messages appearing in Mail in this order:
"get first message of inbox" will return the Message dated 1/5/16 from the "My Gmail" account (G comes before i, 1/5/16 comes before 1/10/16).
My guess is that you have more than one account in Mail.
Name the specific mailbox. This will always set theMessage to the newest message in "My Gmail". (The account name is the same name you see in Mail in the list under Inbox).
This is an unusual approach, however, as mail moves, so the first message in your mailbox could become your second message unexpectedly.
Here are a couple of reliable ways to extract data from messages:
Use selected messages (messages you've selected by clicking on them in Mail):
Mail Rules (run a script on messages that match certain criteria). In Mail, open Preferences > Rules. Create a new rule with "Run AppleScript" as the action. Select "Open in Finder" from the menu that lets you select which script to run. Open Script Editor, and save the code below as a script in the folder Mail opened. Back in Mail, select your saved script as the script to run: