jdfwarrior

Search Mail.app Workflow

36 posts in this topic

Search Mail.app for email messages matching the search query passed.

 

http://d.pr/f/FVd2

 

A few have reported with this not working so I went back and added the option in mdfind to search in a specific folder so that hopefully it would find those results. Report any issues

 

UPDATE: Based on schoeps comment below, I realized that the search I was performing was queueing off of kMDItemKind == 'Mail Message' and depending on your local language, that may not be the appropriate value. So I changed it to search on kMDItemContentType which should be the same across the board. I have confirmed that it works in English and Italian at least.

 

UPDATE: I removed the -onlyin argument from mdfind. Removing the specified folder helps in finding the files with alternate language OS's.

drking, cortig, Weaselboy and 2 others like this

Share this post


Link to post

Not getting any results.

 

Is it restricted to the inbox? As I have a inbox zero right now, so that could explain it in that case.

The account in question is an Exchange account, if that makes any difference.

Share this post


Link to post

Are you typing more than 3 characters? It doesn't start until there are 3 characters typed.

 

It isn't restricted to Inbox. It finds in all folders, it's using mdfind to search for mail documents (.emlx files).

 

I don't understand why it isn't working for some.. I've tested on all of my machines (iMac, Macbook Air, and Hackintosh), @binaryghost tested it, and a friend at work and it worked perfectly for all of us.. hrm.. Guess I'll keep trying.

 

If anyone else has success, please let me know so I can confirm that I'm not going crazy

Share this post


Link to post

Hi, it might be a language issue. On my German system 

 

mdfind -live "kMDItemKind == 'Mail Message'

 

does not work, but

 

mdfind -live "kMDItemKind == 'E-Mail'"

 

returns plenty of mails.

Share this post


Link to post

Oh hrm.. thanks for the info.. I'll have to check and see if I can find the OS language and then adjust the query based on that

Share this post


Link to post

Perhaps one of the reasons people think it doesn't work (apart from the language thing) is that it can take a while to return results - as the search is triggered for each key press, they can 'queue' up and your finial search query can take a while to be performed. My inbox has several hundred thousand messages in from across many folders, from mailing lists etc. While limiting the search to not kick in until 3+ characters has improved the speed, it's still slugish. 

 

Does Alfred have anyway of 'delaying' the execution of the workflow script, for say a few hundred milliseconds (configurable on the workflow)? That way searching for messages from "Jo blogs", the search won't actually start until you've finished typing - unless you are a really slow typer - but the results will appear almost instantly. 

 

I can see other benefits of this - especially on the extensions that go off to other web based APIs. 

Share this post


Link to post

Guys, if you don't mind, I just posted a new version of it. Check the note in the first post about what I changed. Let me know if this fixes things. 

 

Thanks

Share this post


Link to post

Hmpf, still not getting any results.

I tried search terms that definitely should be found and even waited some time. No luck here on a german system.
But I really appreciate your restlessness :-) 

Share this post


Link to post

Do me a favor?

 

1. Drop to a terminal.

2. Run:

mdfind "kMDItemContentType == 'com.apple.mail.emlx'"

 

Do you get results?

 

If no, try

mdfind -onlyin "<yourhomepath>/Library/Mail/V2/" "kMDItemContentType == 'com.apple.mail.emlx'"

 

Results now?

Share this post


Link to post

This is Great, David, thank you very much, this is timely, extremely useful and very much appreciated  :) .

Share this post


Link to post
Do me a favor?

 

1. Drop to a terminal.

2. Run:

mdfind "kMDItemContentType == 'com.apple.mail.emlx'"

 

Do you get results?

 

If no, try

mdfind -onlyin "<yourhomepath>/Library/Mail/V2/" "kMDItemContentType == 'com.apple.mail.emlx'"

 

Results now?

Your first terminal command works and results in a lot of .emlx files as output!

Share this post


Link to post

Your first terminal command works and results in a lot of .emlx files as output!

Ok then we're getting somewhere. The second command is exactly what is used in the workflow. I was trying to target the exact area where the files were but maybe that is different in the alternate languages as well. I'll get a revision posted soon

Share this post


Link to post

I found out why this didn't work for me.

 

"printf $HOME" results in my home folder path with a trailing "%".

If I changed the home path line to "$home = str_replace('%','',exec('printf $HOME'));" the workflow started to work for me.

 

I use ZSH as my standard shell, perhaps that is whats causing it, because I get no trailing "%" when i start BASH and run the command through that.

Share this post


Link to post
I found out why this didn't work for me.

 

"printf $HOME" results in my home folder path with a trailing "%".

If I changed the home path line to "$home = str_replace('%','',exec('printf $HOME'));" the workflow started to work for me.

 

I use ZSH as my standard shell, perhaps that is whats causing it, because I get no trailing "%" when i start BASH and run the command through that.

 

Ah, interesting. Glad you were able to figure it out. I haven't used ZSH in a while so I would have never caught that.

Share this post


Link to post

Thanks for a great workflow. The plugin seems to not work from time to time.  When this happens, I find one of the following errors in /usr/log/system.log

 

Jan 22 16:18:53 SCH-BP-2003.local Alfred 2[8287]: [ERROR] Script XML Parse Error occured Error Domain=NSXMLParserErrorDomain Code=26 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 26.)"

or:

Jan 22 16:10:34 SCH-BP-2003.local Alfred 2[8287]: [ERROR] Script XML Parse Error occured Error Domain=NSXMLParserErrorDomain Code=4 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 4.)"

Share this post


Link to post

Would it be possible to modify this to narrow the search using specific folders? i.e., search flagged mail OR search VIP mail. 

 

Thanks!

drking likes this

Share this post


Link to post

Probably but I would have to add some kind of id for it to know what's what you were doing. For instance:

Mail @flagged <search>

Share this post


Link to post

The Workflow sure works great for me, but I'm trying to understand your approach (and create other workflows on the same idea for other e-mail clients).

Why use a script at all? Can the same thing be done with a filter?

You can limit the scope to ~/Library/Mail/V2 and use the kMDItemAuthorEmailAddresses, kMDItemAuthors and kMDItemSubject metadata fields.

What's wrong with that approach?

 

I'm unsure how it all works, because I've ran into a few things I couldn't figure out when I tried (eg: using kMDItemContentType didn't seem to make any difference at all, that's why I eventually had to resort to limiting the scope).

 

 

          Corentin
 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now