function getSelection () { return Application('Finder') .selection() .map(item => urlToPath(item.url())) .join('\n') } function getPath () { const windows = Application('Finder').windows() if (!windows.length) { throw new Error('No Finder windows open') } else { return urlToPath(windows[0].target().url()) } } function urlToPath (url) { if (!url.startsWith('file://')) { throw new Error(`Unexpected URL scheme: ${url}`) } return $.NSURL.alloc.initWithString($(url)).fileSystemRepresentation }