Previous | Index | Next |
URL and File related methods
runSpotlightQuery:inFolders:error:
Conduct a Spotlight metadata search. The query string needs to be a valid Spotlight query, such as "kMDItemFSInvisible = YES". listOfFilesPathsURLsOrQueryScopeConstants can contain aliases, files, HFS paths, POSIX paths or NSURLs, as well as query scope constants such as 'current application's NSMetadataQueryLocalComputerScope'. Returns an array of POSIX paths, or missing value if there is an error.
+ (NSArray *)runSpotlightQuery:(NSString *)queryString inFolders:(NSArray *)listOfFilesPathsURLsOrQueryScopeConstants error:(NSError *__autoreleasing *)outError
queryString = valid Spotlight query string
listOfFilesPathsURLsOrQueryScopeConstants = aliases, files, HFS paths, POSIX paths or NSURLs, as well as query scope constants such as 'current application's NSMetadataQueryLocalComputerScope'
outError = missing value or reference
Array of POSIX paths
Version 1.3.0
If you set outError to reference, the result will be a list of two items. If there is no error, the first item will be the result of the method and the second will be missing value. If there is an error, the first item will be missing value and the second item with be an NSError.
use scripting additions
use framework "Foundation"
use script "BridgePlus"
load framework
set theResult to current application's SMSForder's runSpotlightQuery:"kMDItemContentTypeTree CONTAINS 'public.image'" inFolders:{(path to desktop)} |error|:(missing value)
ASify from theResult
--> <list of image files on desktop, searching recursively>
theResult as list
--> <list of image files on desktop, searching recursively>
set {theResult, theError} to current application's SMSForder's runSpotlightQuery:"invalid query" inFolders:{(path to desktop)} |error|:(reference)
if theResult = missing value then error (theError's localizedDescription() as text)
--> error number -10000 Unable to parse the format string "invalid query"