How LaunchServices builds the Open Recent menu, and outsmarts Aliases

Finder Aliases are in many cases a significant improvement on symbolic links, but they’re far from perfect. When an Alias breaks, you’re given no clue as to why, just an offer to fix the Alias, delete it, or ignore the issue. But using the information stored in an Alias or a Bookmark, macOS could be more helpful. An interesting illustration of what more it could do is how LaunchServices builds the list of recently used documents for the Open Recent command.

To demonstrate this, you’ll need an external drive on which to save a file. If you try this with a disk image, you’ll encounter a helpful behaviour which is common to both Aliases and LaunchServices’ handling of Bookmarks that I’ll mention below, and which prevents you from seeing the distinctive dialog.

Open a ‘regular’ app which features the Open Recent menu, create a test document in it, save that to your external drive, and close the document. As you’d expect, at the top of the Open Recent menu is the document which you just saved; confirm that selecting that item opens your document, and close it again.

openrecent00

Now eject the external drive, and once it has unmounted from the Finder, open the Open Recent menu again. You’ll see that document still listed at the top, even though you know that its volume is missing, and the file currently inaccessible. If you now try to open that document, you’ll see this alert informing you that the document is unavailable, but if you mount the named volume you should be able to open it again.

openrecent01

If you had created an Alias to that document, then ejected the volume and tried to open the Alias, you’d have seen the generic broken Alias dialog, which doesn’t give a clue as to what has gone wrong.

openrecent02

Where this gets more puzzling is when handling deleted files. As I wrote in an earlier article, LaunchServices stores these Bookmarks in an sfl2 file in ~/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments/ for each application. But once an entry has been added there, LaunchServices doesn’t maintain its entry in the light of attempts to open the document pointed to by each Bookmark. Here it’s important to recognise that LaunchServices is performing a different task to following an Alias in the Finder: it’s using its Bookmarks to build a menu, not to help you navigate your files.

Re-mount your external volume, and put your test document in the Trash without emptying it. Now it has disappeared from the Open Recent menu, but should return if you replace the document from the Trash. With the document in the Trash, empty it or otherwise remove the document from that external drive (rm is fine if you prefer), then eject it again.

When you now open the Open Recent menu, the document is back at the top of the list of documents. What has happened is that LaunchServices has rescanned the sfl2 file for the app, and discovered that the volume for that (now deleted) file is missing. Instead of omitting the document from the menu, it replaces it, only to report that its volume can’t be found, should you try to open it.

That might seeem dumb, but the alternative would require LaunchServices to remove items it believes to have been deleted from its sfl2 files, making it impossible to access them from the Open Recent menu until you have located the file again and opened it in the app. As things stand at present, if you were to attach external storage on which a document was missing, you could still try to open it via Open Recent, see the warning, and restore the missing file from another source.

If you were to restore the document with the same name and path as the original, LaunchServices should add its name back to the Open Recent menu when you mount the external storage again. This also allows you to spoof LaunchServices by replacing the original file with something different, should you wish.

Try any of these steps using a disk image stored locally, though, and you’ll encounter another behaviour of both Finder Aliases and LaunchServices’ Bookmarks: try resolving a link to a file on a recently-mounted disk image that has been ejected, and you’ll find that macOS automagically remounts the disk image before following that link for you.

I have assembled my understanding of LaunchServices’ behaviour when building the list of items for the Open Recent menu into the diagram below.

openrecent03

That contrasts with the normal resolution of Aliases and Bookmarks shown below.

aliassummary1

Could LaunchServices do better? Yes, it could if it were to maintain its sfl2 lists of recent items by removing those which it can no longer find. The penalty then is that, once an item has been deleted from the list, LaunchServices wouldn’t then be able to offer the user the clue that an item had been on a volume which is no longer mounted, and it would then be as unhelpful as a mere Alias. On balance, I think LaunchServices is more helpful to the user even if it does lead to the occasional puzzle.

(Thanks to Jeff Johnson @lapcatsoftware for instigating this, even though we differ completely on its interpretation.)