MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / readClipboardFilePathMacOS

Function readClipboardFilePathMacOS

cli/src/utils/clipboard-image.ts:406–447  ·  view source on GitHub ↗

* Read file URL/path from clipboard when a file has been copied (e.g., from Finder). * Returns the POSIX path if a file URL is found, null otherwise. * * When you copy a file in Finder (Cmd+C), the clipboard contains a file reference, * not plain text. pbpaste won't return the path, but we can

()

Source from the content-addressed store, hash-verified

404 * extract it.
405 */
406function readClipboardFilePathMacOS(): string | null {
407 try {
408 // First check if clipboard contains a file URL
409 const infoResult = spawnSync('osascript', [
410 '-e',
411 'clipboard info',
412 ], { encoding: 'utf-8', timeout: 1000 })
413
414 if (infoResult.status !== 0) return null
415
416 const info = infoResult.stdout || ''
417 // Check for file URL type in clipboard (furl = file URL)
418 if (!info.includes('«class furl»') && !info.includes('public.file-url')) {
419 return null
420 }
421
422 // Extract the file path using AppleScript
423 const script = `
424 try
425 set theFile to the clipboard as «class furl»
426 return POSIX path of theFile
427 on error
428 return ""
429 end try
430 `
431
432 const result = spawnSync('osascript', ['-e', script], {
433 encoding: 'utf-8',
434 timeout: 1000,
435 })
436
437 if (result.status === 0 && result.stdout) {
438 const filePath = result.stdout.trim()
439 if (filePath && existsSync(filePath)) {
440 return filePath
441 }
442 }
443 return null
444 } catch {
445 return null
446 }
447}
448
449/**
450 * Read file path from clipboard when a file has been copied (Windows).

Callers 1

readClipboardFilePathFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected