`...Failed to get state for list identifier com.apple.LSSharedFileList.ApplicationRecentDocuments Error...` in console

I am recently developing a Document-Based App by Xcode v13.1

I find there is some unexpected messages output in the console as below

2022-07-14 18:18:22.182714+0800 TestApp[31090:987991] [default] Failed to get state for list identifier com.apple.LSSharedFileList.ApplicationRecentDocuments Error: Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted" (Access to list denied) UserInfo={NSDebugDescription=Access to list denied}
...
2022-07-14 18:19:28.460021+0800 TestApp[31090:988415] [default] Insert failed for list identifier com.apple.LSSharedFileList.ApplicationRecentDocuments Error: Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted" (Access to list denied) UserInfo={NSDebugDescription=Access to list denied}

By testing, I find a problem that the recently opened is unavailable on my App, (App Menu > File > Open Recent sub-menu is always empty)

As makabaka1880 said in the thread https://developer.apple.com/forums/thread/707260, it is a trigger to set Signing Certificate from Development to Sign to Run Locally

Therefore, we can avoid this kind of problem via one of the following temporary solutions:

  • removing the App Sandbox
  • keeping Signing Certificate being Development
  • changing the Bundle Identifier to the other available

Go deeper. How can we solve the problem fundamentally?

According the description of makabaka1880, we can conclude that the Failed Bundle Identifier has be recorded in somewhere not in the project folder.

By turning over the folder ~/Library/ using find and grep, removing non essential documents, especially whose name is similar to LSSharedFileList, even using the defaults command to delete relative App information, the problem is still unsolved.

Finally, I find a document about the sharedfilelist:https://eclecticlight.co/2017/08/10/recent-items-launch-services-and-sharedfilelists/

There is a command quoted in the document: killall sharedfilelistd

To stop the process can ensure that the Failed Bundle Identifier record is not existing on memory. By way of practice, another necessary operation is to remove relative data in the hard disk.

Here is the finally solution can be executed on console:

rm -rf ~/Library/Application\ Support/com.apple.sharedfilelist/ && killall sharedfilelistd
Answered by persquare in 726533022

I ran into this problem when reusing a Bundle Identifier in a new project. The above information helped me solve it, but cleaning out everything in com.apple.sharedfilelist/ seem a bit overkill as it would remove recent files from all applications.

You could try using finder to delete just the file associated with your app. Either browse your way there, or run the following in a terminal:

open ~/Library/Application\ Support/com.apple.sharedfilelist/

Locate the file named with your Bundle Identifier (e.g. org.you.AppName.sfl2) and trash it.
Then run

killall sharedfilelistd
Accepted Answer

I ran into this problem when reusing a Bundle Identifier in a new project. The above information helped me solve it, but cleaning out everything in com.apple.sharedfilelist/ seem a bit overkill as it would remove recent files from all applications.

You could try using finder to delete just the file associated with your app. Either browse your way there, or run the following in a terminal:

open ~/Library/Application\ Support/com.apple.sharedfilelist/

Locate the file named with your Bundle Identifier (e.g. org.you.AppName.sfl2) and trash it.
Then run

killall sharedfilelistd

Here's what helped in my case. What I was trying to do:

  • Insert a file url into NSDocumentController's recent document list programmatically. It was originally opened by NSOpenPanel on an earlier run but then its path was saved to a file for opening later. My application manages the recent list manually based on its own records.

What happened:

  • It appeared in the File menu recent list, but Clear Menu remained grayed out.
  • I got the "Insert failed for list identifier com.apple.LSSharedFileList.ApplicationRecentDocuments" error message

What caused this:

  • The application was not permitted to access the file that I was trying to insert into the recent list.

What fixed the problem:

  • I had to read in the bookmark that I saved on the earlier run, and call startAccessingSecurityScopedResource on it, before inserting it into the recent list.
  • Even after inserting into the list, the app should not call stopAccessingSecurityScopedResource, until the item is removed from the recent list.
`...Failed to get state for list identifier com.apple.LSSharedFileList.ApplicationRecentDocuments Error...` in console
 
 
Q