Get path from OS X file reference URL alias (file:///.file/id=...)

In Swift you can use URL.standardized to get the valid path from a reference URL. So in Swift 4 - to get the file name from a drag-and-dropped file you'd do something like...

let fileType = NSPasteboard.PasteboardType (kUTTypeFileURL as String)

extension NSPasteboardItem {
    func fileURL ()->URL? {
        if let refURL = self.string(forType: fileType) {
            return URL (fileURLWithPath: refURL).standardized
        }
        return nil
    }
}

One can use osascript, an AppleScript interpreter available on default OS X installs, run with the following script:

osascript -e 'get posix path of posix file "file:///.file/id=123.456" -- kthxbai'

Prints /Users/josh/Downloads/paste-10837081.py.