Go Back   The macosxhints Forums > OS X Help Requests > UNIX - Newcomers



Reply
 
Thread Tools Rate Thread Display Modes
Old 12-19-2006, 12:18 PM   #1
NovaScotian
League Commissioner
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 5,155
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?
__________________
17" MBP, OS X; 27" iMac, both OS X 10.10.x (latest)

Last edited by NovaScotian; 12-19-2006 at 12:25 PM. Reason: Correction
NovaScotian is offline   Reply With Quote
Old 12-19-2006, 01:26 PM   #2
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
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.
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 12-19-2006, 01:30 PM   #3
NovaScotian
League Commissioner
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 5,155
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.
__________________
17" MBP, OS X; 27" iMac, both OS X 10.10.x (latest)

Last edited by NovaScotian; 12-19-2006 at 01:48 PM.
NovaScotian is offline   Reply With Quote
Old 12-19-2006, 02:32 PM   #4
bramley
MVP
 
Join Date: Apr 2004
Location: Cumbria, UK
Posts: 2,461
Quote:
Originally Posted by NovaScotian
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
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.
bramley is offline   Reply With Quote
Old 12-19-2006, 03:59 PM   #5
NovaScotian
League Commissioner
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 5,155
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.
__________________
17" MBP, OS X; 27" iMac, both OS X 10.10.x (latest)
NovaScotian is offline   Reply With Quote
Old 12-27-2006, 06:36 PM   #6
NovaScotian
League Commissioner
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 5,155
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).
__________________
17" MBP, OS X; 27" iMac, both OS X 10.10.x (latest)
NovaScotian is offline   Reply With Quote
Old 12-27-2006, 07:11 PM   #7
Hal Itosis
Hall of Famer
 
Join Date: Apr 2002
Posts: 3,315
Quote:
Originally Posted by NovaScotian
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-
Hal Itosis is offline   Reply With Quote
Old 12-27-2006, 07:31 PM   #8
NovaScotian
League Commissioner
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 5,155
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
__________________
17" MBP, OS X; 27" iMac, both OS X 10.10.x (latest)

Last edited by NovaScotian; 12-27-2006 at 08:28 PM. Reason: Changed Conclusion then added info
NovaScotian is offline   Reply With Quote
Old 12-28-2006, 08:24 AM   #9
Hal Itosis
Hall of Famer
 
Join Date: Apr 2002
Posts: 3,315
Quote:
Originally Posted by NovaScotian
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.

Last edited by Hal Itosis; 12-28-2006 at 08:36 AM.
Hal Itosis is offline   Reply With Quote
Old 12-28-2006, 09:25 AM   #10
NovaScotian
League Commissioner
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 5,155
Thanks Hal;

Very useful.
__________________
17" MBP, OS X; 27" iMac, both OS X 10.10.x (latest)
NovaScotian is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



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.