How to find and open an email in Apple Mail with a specific word in the subject line


I wrote a macro to process (open a URL link in the email, etc) a specific type of email containing the term 'POEM:' at the beginning of the subject line (POEM is a technical acronym; I am not a poet). Please note that the text following POEM: in the subject line varies with each email I have to process.

The macro works fine if I open apple mail and highlight the email in question.

I would like to add the following instructions to the beginning of the macro:

  • activate apple mail (no problem, I know the action)
  • go to the the inbox, search for and highlight the email whose subject starts with POEM: (there will be only one such email at any one time).
  • open that email (just type return which I know how to do in a macro).

after that, I will run the rest of the macro

thanks very much

If you're using Apple Mail, the best way to go about something like this is to use AppleScript:

tell application "Mail"
	open (get first message of inbox whose subject begins with "POEM")
end tell

This one script used in an Execute an AppleScript action can replace every action you describe in your post by itself. However, you can also do much more. As a simple example, this Execute an AppleScript action will create a KM variable with the entire body/text of the email:

Execute an AppleScript.kmactions (752 Bytes)

tell application "Mail"
	return content of (get first message of inbox whose subject begins with "POEM")
end tell

Which from there can of course be processed in the same way as any KM variable.

If the rest of your macro works for you and you'd rather not mess with it beyond this step, I understand perfectly, but in case you're willing and able to share the entire workflow you'd like to accomplish, I'm sure that someone here could help you figure out a more efficient and accurate way of doing so.


thanks very much !

Hey @ronald,

Give this a try.


Mail ⇢ Open InBox Message with Subject Prefixed "POEM-".kmmacros (5.7 KB)

1 Like

Just curious - I don't need this done, but could it be done with Gmail?__

Hey @jsmith85,

Not from a web browser UI.

Using Apple Mail with a Gmail account? Maybe.

There have been some issues in the past with scripting Gmail inside of Mail, and I don't do it often enough to know if they've been resolved.


1 Like

Thanks very much for creating a macro.

I tried it many times and it does not seem to work reliably. Sometimes yes, sometimes no.

I can't figure out why. Related to tabbing ?

thanks again for your help

By the way, i looked up out of curiosity but didn't find a web site. Probably just an email address.

Hey @ronald,

You're saying that your macro doesn't work reliably? Or mine?

Tabbing around Mail's UI can get you into trouble on occasion. It's best to avoid doing so if possible.

If you just go to my domain you'll find a very sparse page:

“If you've found yourself here you're quite lost…”



1 Like

your macro. I will work on finding where I can remove mail tabbing.

I only looked at your web site because you are so creative and productive on this forum. I thought that I would discover a treasure chest of ideas.

thanks again

Hey @ronald,

Hmm... My macro should be pretty reliable.

The two things I can think of offhand that might interfere are:

1) A zillion items in the InBox.

2) Spotlight hasn't had time to index incoming mail yet.


1 Like

8 posts were split to a new topic: How Do I Scroll Down to View Image/Link to Click on?

@ronald, since your OP has been answered/solved, I am going to move the remainder of the discussion to a new topic, since it is a very different subject.

Please check the "Solved" checkbox (click for details) at the bottom of the post solves your problem/question as originally stated.

1 Like

done. thank you

works perfectly. thanks very much