• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: mdfind ­ How to Find a Specific Word?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mdfind ­ How to Find a Specific Word?


  • Subject: Re: mdfind ­ How to Find a Specific Word?
  • From: Jim Underwood <email@hidden>
  • Date: Wed, 15 Mar 2017 03:52:55 +0000
  • Thread-topic: mdfind ­ How to Find a Specific Word?

Chris,

You can use the "contains" operator with BridgePlus.
Here's an example, that I thought I got from you or Shane some time ago:



use AppleScript version "2.4" -- Yosemite (10.10) or later

use framework "Foundation"


use scripting additions

use script "BridgePlus" ## REQUIRED SCRIPT LIB ###

load framework


--- SEARCH FOR ALL VIDEO (MOVIE) TYPES ---

--    public.movie:  Base type for movies (video with optional audio or other tracks).

--    See: https://tinyurl.com/Apple-UTI


set mdQueryStr to "kMDItemContentTypeTree CONTAINS 'public.movie'"


set folderToSearch to (choose folder) as alias


set fileList to my spotSearch(folderToSearch, mdQueryStr)


--~~~~~~~~~~~~~~~~~~~ END MAIN SCRIPT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


on spotSearch(pFolderToSearchAlias, pQueryStr)

  

  set nsFileList to current application's SMSForder's runSpotlightQuery:pQueryStr inFolders:{pFolderToSearchAlias} |error|:(missing value)

  

  --- ALTERNATE QUERY ---

  --set theResult to current application's SMSForder's runSpotlightQuery:pQueryStr queryValues:{pQueryValues} inFolders:{pFolderToSearchAlias} |error|:(missing value)

  

  ASify from nsFileList

  

  --- RETURN as POSIX File List ---

  return nsFileList as list

  

end spotSearch




REFERENCES:

  1. BridgePlus Script Library v1.3.2 by Shane Stanley
        https://www.macosxautomation.com/applescript/apps/BridgePlus.html
  
      BridgePlus.framework, SMSForder Class Methods
      https://www.macosxautomation.com/applescript/apps/BridgePlus_Manual/Pages/runSpotlightQuery_inFolders_error_.html
  
  2. Common Spotlight Metadata Attribute Keys
        https://tinyurl.com/Apple-Spotlight-Keys
  
  3. System-Declared Uniform Type Identifiers (UTI)
        https://tinyurl.com/Apple-UTI
  
  4. Spotlight syntax, mdfind examples, and metadata attributes
    http://osxnotes.net/spotlight.html




Best Regards,

 

Jim Underwood

aka JMichaelTX


From: <applescript-users-bounces+jmichael=email@hidden> on behalf of Chris Stone <email@hidden>
Date: Tue, Mar 14, 2017 at 3:38 PM
To: "ASUL (AppleScript)" <email@hidden>
Subject: mdfind – How to Find a Specific Word?

Hey Folks,

This Spotlight query finds all items whose name contain the string “find”:

cd ~/'Documents/Scripts (Library)/Application Scripting/AppleScriptObjC { ASObjC }'
mdfind -onlyin . 'kMDItemFSName == "*find*"c'

So – all items containing the word “Finder” are also found.

I would like to reduce that to only the items whose names contain the WORD “find”.

Presently the only way I know how to do this is to post-process the mdfind results.

Is there a way to force Spotlight to find what I want?

TIA.

--
Best Regards,
Chris


_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >mdfind – How to Find a Specific Word? (From: Christopher Stone <email@hidden>)

  • Prev by Date: Re: notes to pdf
  • Next by Date: Re: mdfind – How to Find a Specific Word?
  • Previous by thread: Re: mdfind – How to Find a Specific Word?
  • Next by thread: Re: mdfind – How to Find a Specific Word?
  • Index(es):
    • Date
    • Thread