Jump to content

Search Mail.app Workflow


Recommended Posts

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.

Link to comment

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

Link to comment

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. 

Link to comment
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!

Link to comment

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

Link to comment

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.

Link to comment
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.

Link to comment

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.)"
Link to comment

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
 
Link to comment

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
×
×
  • Create New...