LaunchServices and Spotlight

By admin
LaunchServices and Spotlight


October 14 2023
DATE


A few days ago
DATE

,

Howard Oakley
PERSON

wrote an article LaunchServices problems in

Sonoma
GPE

14.0, I wrote a comment on the article, and

today
DATE


Howard
PERSON

wrote a follow-up article LaunchServices problems and

Ventura
GPE

. This article is a follow-up to

Howard
PERSON

‘s follow-up. You should read

Howard
PERSON

‘s articles before mine, otherwise mine might not make much sense, and I don’t want to repeat everything here that’s already been said.

macOS has a built-in command-line tool for manipulating the

LaunchServices
ORG

database:

/System/

Library/
PERSON

Frameworks/ CoreServices.framework/ Versions/A/ Frameworks/

LaunchServices.framework/ Versions
PERSON

/A/ Support/ lsregister

In my .zshrc file, I have an alias lsregister for that path. Enter the command with no arguments to see usage information. To unregister an app or apps from the

LaunchServices
ORG

database, use the following arguments, followed by the path of the app or apps:


lsregister
PERSON

-R -f -u -v

The argument -R is "

Recursive directory scan
WORK_OF_ART

, descending into packages and invisible directories", -f is "force-update registration even if mod date is unchanged", -u is "unregister instead of register", and -v is "Display progress information" (in other words, verbose).

Unfortunately, the verbose option has been broken since

Monterey
GPE

. I filed feedback with

Apple
ORG

, FB9986535 "lsregister -v verbose option no longer works on

Monterey
GPE

", in

April 2022
DATE

.

I have a very specific workflow for unregistering apps with

LaunchServices
ORG

. Again, I have a .zshrc alias for this:

alias ‘

archives=/System/
NORP

Library/ Frameworks/ CoreServices.framework/ Versions/A/ Frameworks/

LaunchServices.framework/ Versions
PERSON

/A/ Support/ lsregister -R -f -u -v ~/Developer/ Xcode/ Archives’

The reason for this workflow is an Xcode bug: FB10829413 "Organizer window registers

Archives
ORG

with LaunchServices", which I filed in

July 2022
DATE

. Whenever I open the

Xcode Organizer
ORG

window, which shows archives of my

App Store
ORG

apps, crash reports, and other information, every archived copy of my

App Store
ORG

apps gets registered with

LaunchServices
ORG

. As a result, the Open With contextual menu in Finder looks like this:

You can see multiple versions of my app

Link Unshortener
PERSON

with its newer (pretty) and older (ugly) icons. To clean up the contextual menu, I have to run my archives command, and then it likes look this:

On

Ventura
GPE

, lsregister started to return an error "failed to scan" with the error code -10814. However, this error appears to be harmless, and that’s what I wrote in my comment to

Howard
PERSON

‘s original article.

In the follow-up article,

Howard
PERSON

wrote:

And, in both

Ventura
GPE

and

Sonoma
GPE

, as

Jeff
PERSON

reports, the command does what it should regardless of the error message. However, removal is transient, and depends on there being no copy of that app on any local volume. Unless you compress the app or otherwise render it inaccessible, even force restarting the

Finder
ORG

will restore it to the Open With menu.

As a side note, here’s an ancient but still effective trick to add a Quit menu item to Finder:

defaults write com.apple.finder QuitMenuItem -bool YES

(

Logout
PRODUCT

and login for the change to take effect.)

Back to the gist of

Howard
PERSON

‘s response, his experience with lsregister was not the same as my experience. For me, my old archived apps remain absent from the Open With contextual menu even after quitting Finder (until the next time I open the Xcode Organizer window, sigh). What accounts for this difference? The reason, it turns out, is that I excluded the Xcode Archives folder in

Spotlight’s Privacy System Settings
ORG

. This means my old archived apps never appear in Spotlight searches, even when they do appear in the Open With contextual menu. In contrast, when Spotlight can find an app, it registers the app with

LaunchServices
ORG

. That’s why unregistering with

lsregister
PERSON

appears to be a futile endeavor for apps that are located in folders and volumes indexed by Spotlight.


Howard
PERSON

writes:

Maybe I haven’t been paying attention, but

LaunchServices
ORG

now searches all mounted local volumes, probably using Spotlight, to discover apps to include in its database.

At least as far as mounted boot volumes are concerned, this has been a longstanding problem with Spotlight. For the purpose of testing, I have a

Mac
ORG

mini with

four
CARDINAL

different macOS versions installed on

four
CARDINAL

separate

APFS
PERSON

volumes. The same problem with multiple app versions appearing in the Open With contextual menu occurs in each of these

four
CARDINAL

macOS versions, from

Sonoma
GPE

to Big Sur (and has occurred in the past with previous macOS versions).

Spotlight has never handled multiple boot volumes well, unfortunately.

Apple
ORG

likes to pretend that nobody ever uses this configuration. It doesn’t even help to exclude volumes from

Spotlight Privacy System Settings
ORG

, because the exclusion seems to be stored by the excluded volume rather than by the excluding volume. The sad result is that if you exclude the

Ventura
GPE

volume from Spotlight while running

Sonoma
GPE

, the

Ventura
GPE

volume will also be excluded from Spotlight while running

Ventura
GPE

!

Way back in

2009
DATE

, I filed

FB5666683
PRODUCT

(originally

Radar
PRODUCT

6939726) "Spotlight: no way to set separate Privacy prefs for multiple OS X partitions". That bug report was closed as a duplicate; I don’t have any further tracking information. And in

2008
DATE

, I filed FB5950134 (originally

Radar 6338139
PRODUCT

) "Spotlight: preference to not index external drives". That was also closed as a duplicate.


Howard
PERSON

suggested in his original article that there has been a change of behavior on

Sonoma
GPE

:

After upgrading to

Sonoma
GPE

,

one
CARDINAL

difference that you may notice is that the lists of apps capable of opening some types of document have expanded to include copies of apps not located in any of the conventional

Applications
ORG

folders. In my case, where I keep old versions of my own apps on an external SSD, every one of those now appears in the popup menu to Open With.

This may be true, though I haven’t attempted to test it specifically. If there has been a change in

Sonoma
GPE

, it would involve a change in the list of folders indexed by Spotlight. My theory is that any addition of apps to the Open With contextual menu in

Sonoma
GPE

would coincide with the addition of those same apps to the Spotlight search results.