In case anyone else is struggling with getting "open recent" to work in a non-document based app... this may help.
You have likely written your own 'open file' function, probably in your ViewController... somewhere in there drop this line:
NSDocumentController.shared.noteNewRecentDocumentURL(myFileURL)
where myFileURL is an unwrapped URL (not NSURL, and definitely not a string). This line instantiates the document controller and should get your URL (now magically shortened to just the file name!) to the open recent menu. You do not need to instantiate the document controller elsewhere, this line does that.
Now that the menu is being fed URLs from your app, you need to create the logic to open a file when the user selects a file to open. In your AppDelegate, create this function:
func application(_ sender: NSApplication, openFile filename: String) -> Bool {
let url = URL(fileURLWithPath: filename)
if let controller = NSApplication.shared.mainWindow?.contentViewController as? ViewController {
let result = controller.openFunction(url: url)
return result
} else {
print("could not instantiate controller object in AppDelegate.")
return false
}
}
Notice: the URL is being returned as a string. The next line turns it back into a URL, and even handles white space, which the usual let url = URL(string: filename) does not. In the next line I will instantiate a handle to my ViewController class, if your file opening logic is elsewhere, instantiate accordingly. The next line calls my 'openFunction' function in my viewController, which takes a URL and returns a bool related to the success of opening the file. This is now functional in my app, hopefully it will work in your own.