1

I have a macOS project in Swift where I would like to get file paths for current open documents. How can this be achieved?

EDIT: I mean the open documents of the app itself. Typically represented as windows or tabs.

PS I check these questions but don't help: How to get file path? Loading documents in Document based app Cocoa question: How to get file path for current open document for the front most application

Willeke
  • 14,578
  • 4
  • 19
  • 47
Cue
  • 2,952
  • 3
  • 33
  • 54

1 Answers1

2

You can get the documents from NSDocumentController and the URL from each document.

for document in NSDocumentController.shared().documents {
    print("\(document.fileURL)")
}
Willeke
  • 14,578
  • 4
  • 19
  • 47