The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   UNIX - Newcomers (http://hintsforums.macworld.com/forumdisplay.php?f=15)
-   -   Using mdfind questions (http://hintsforums.macworld.com/showthread.php?t=65023)

NovaScotian 12-19-2006 12:18 PM

Using mdfind questions
 
In another thread, Hayne used mdfind with an attribute equality to find all applications on a volume. Specifically, he used:

mdfind 'kMDItemContentTypeTree == \"com.apple.application\"c'

Having spent some time exploring mdfind, I'm left with some questions. Why use mdfind 'kMDItemContentTypeTree == "com.apple.application"c' as opposed to 'kMDItemkind == "Application"', and what is the follow-on "c" doing?

The content type of an application seems to be "com.apple.application-bundle" for those I've looked at. Was the objective to capture apps that were not bundles as well?

I note after some testing that kind == "Application" vs ContentTypeTree == "com.apple.application"c lists differ by quite a few applications whereas the difference between ContentTypeTree == "com.apple.application-bundle and kind == "Application" is that the latter includes all the AppleScript apps on the target volume (using -onlyin /). Except by experiment, is there a reference for what to expect here?

hayne 12-19-2006 01:26 PM

The documentation on 'mdfind' isn't the greatest. Here's the best I've found:
http://developer.apple.com/documenta...Ref/index.html
http://developer.apple.com/documenta...uid/TP40001849

I'm not sure of the answers to your questions. I think I picked up the particular 'mdfind' query you ask about on some developer mailing list sometime.

NovaScotian 12-19-2006 01:30 PM

I'll have to develop a code with you Hayne, you help so often: TYAA == thank you as always.

The secret of "c" is revealed in your reference links: appending a c makes the query case sensitive. "d" makes the query insensitive to diacritical marks, and "w" renders the query word-based, and also detects transitions from lower-case to upper-case.

bramley 12-19-2006 02:32 PM

Quote:

Originally Posted by NovaScotian (Post 343117)
The content type of an application seems to be "com.apple.application-bundle" for those I've looked at. Was the objective to capture apps that were not bundles as well?

It should be so. The UTI 'com.apple.application' should mean all applications (although some forms of executable code are not covered - libraries, frameworks and the like) The UTI 'com.apple.application-bundle' should be all .app applications. And 'com.apple.application-file' should cover applications contained within a single file, such as compiled Applescripts.

There is a list of UTIs here.

There is also a pretty good article on how Apple has worked out UTIs and why here.

Quote:

Originally Posted by NovaScotian (Post 343117)
I note after some testing that kind == "Application" vs ContentTypeTree == "com.apple.application"c lists differ by quite a few applications whereas the difference between ContentTypeTree == "com.apple.application-bundle and kind == "Application" is that the latter includes all the AppleScript apps on the target volume (using -onlyin /). Except by experiment, is there a reference for what to expect here?

Not sure about the first example, but in the second one 'com.apple.application-bundle' will only include applications that are bundles - no applications as files are included. kind == Application will include all bundles and files that are applications.

NovaScotian 12-19-2006 03:59 PM

Thank you Bramley - I've been gathering some of that myself by reading the references Hayne provided, and I'm glad to have your ref to UTIs as well. Given those three references and some experiments by comparing the lists that result, I'll get it sorted.

NovaScotian 12-27-2006 06:36 PM

A follow-on question
 
What is the format (and syntax) required for combining UTIs; i.e.; this and not that, or this AND/OR that? (assuming that is possible for mdfind searches - the man page and Hayne's reference docs are silent on that).

Hal Itosis 12-27-2006 07:11 PM

Quote:

Originally Posted by NovaScotian (Post 344831)
What is the format (and syntax) required for combining UTIs; i.e.; this and not that, or this AND/OR that? (assuming that is possible for mdfind searches - the man page and Hayne's reference docs are silent on that).

Here are some links showing how to do that in the GUI:

http://www.hiram.nl/ipsedixit/artike...h-in-spotlight
http://www.hiram.nl/ipsedixit/artike...t-in-spotlight

No idea if it's of any help for the command line though.

-HI-

NovaScotian 12-27-2006 07:31 PM

Turns out that setting a query to \"YourWords\" will find only files as it does for Spotlight, but OR is not a pipe (which after all has a special meaning in a shell) but is the word "OR".

http://developer.apple.com/documenta...ery/index.html describes the syntax of searches

Hal Itosis 12-28-2006 08:24 AM

Quote:

Originally Posted by NovaScotian (Post 344838)
Turns out that setting a query to \"YourWords\" will find only files as it does for Spotlight, but OR is not a pipe (which after all has a special meaning in a shell) but is the word "OR".

http://developer.apple.com/documenta...ery/index.html describes the syntax of searches

Hmm, I haven't used mdfind all that much. But I did 'find' another web page
which defines the same operators for the CLI that my previous GUI links did:

The Power of mdfind (<-- 4 pages!)

| pipe character means Boolean OR
- minus means to exclude a term
() parentheses create groups

Part of the trick seems to be spaces : if used, they imply 'AND'.
"Quotes" seem more useful in the CLI, 'cause in the GUI they will
limit searches to filenames only (i.e., not contents). <?> I think.

NovaScotian 12-28-2006 09:25 AM

Thanks Hal;

Very useful.


All times are GMT -5. The time now is 01:08 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.