The Spotlight Import Extension does not allow to inspect document bundles to get the metadata for the spotlight

I've made working Spotlight Import Extension with in macOS 15.5 (24F74). mdimport confirm it's installed, and working. The problem is related to accessing data inside document bundles (package directory)

class ImportExtension: CSImportExtension {

  override func update(_ attributes: CSSearchableItemAttributeSet, forFileAt url: URL) throws {
    // ERROR: The file "QuickSort.notepad" couldn't be opened because you don't have permission to view it.
    let fileWrapper = try FileWrapper(url: url)
  }
}

forFileAt url points to a bundle. In order to read the metadata the extension needs to load the bundle from url and access its content, however in the sandbox environment,t the url allows only access to the bundle directory itself in particular NSFileWrapper(url: url) fails with error "The file "name.extension" couldn't be opened because you don't have permission to view it.", and effectively prevent from providing useful metadata.

Is there a way to access the Document Bundle content in order to read the metadata for Spotlight?

Answered by DTS Engineer in 859292022

So, as more direct confirmation, this is in fact correct:

...CSImportExtension was never fully implemented on macOS.

Multiple bugs have been filed on both the extension point and the documentation, but until something changes in the system, the only option is to use the old MDImport API. You can find more information on that in the "Spotlight Importer Programming Guide" from the documentation archive.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

I think this might be the reason CSImportExtension was never fully implemented on macOS, e.g. if you try the built-in pdf extension at /System/Library/Frameworks/PDFKit.framework/Versions/A/Plugins/PDFImporter.appex (from mdimport -L)

Using:

mdimport -m -y com.adobe.pdf -u AnyPDF.pdf

You'll see it doesn't get any attributes like page count or anything, if you have a nosey in Hopper you see it has code for these attributes but is likely failing to read the pdf file in the same way your code does. So they probably gave up and thats why /System/Library/Spotlight/PDF.mdimporter still exists (from mdimport -e ) and why no one can get CSImportExtension to populate spotlight with anything on macOS.

So, as more direct confirmation, this is in fact correct:

...CSImportExtension was never fully implemented on macOS.

Multiple bugs have been filed on both the extension point and the documentation, but until something changes in the system, the only option is to use the old MDImport API. You can find more information on that in the "Spotlight Importer Programming Guide" from the documentation archive.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

The Spotlight Import Extension does not allow to inspect document bundles to get the metadata for the spotlight
 
 
Q