I'm working on an Xcode extension, which needs to get the project path, i.e. the path of the project/workspace from which you run the extension command which I'm making. I've tried something like this:
let workspace = NSWorkspace.shared()
let path = workspace.absolutePathForApplication(withBundleIdentifier: Bundle.main.infoDictionary!["CFBundleIdentifier"] as! String)
but it just returns nil. I have also tried getting it via the FileManager, but it just returns a path of the extension.
App Extensions are always sandboxed, so they don’t have arbitrary filesystem access.
For security, Xcode Source Editor Extensions are also only passed the text of the file for which a user has invoked an action, not the path to the file itself or a sandbox extension allowing access to it or its containing project.