* Check if clipboard contains an image (macOS) * Uses 'clipboard info' which is the fastest way to check clipboard types. * * Note: We do NOT filter out clipboards that contain file URLs here, because * copying images from Finder/Preview/Safari often includes both a file URL * AND the actual i
()
| 41 | * checked first via clipboard text, then we fall back to image data). |
| 42 | */ |
| 43 | function hasImageMacOS(): boolean { |
| 44 | try { |
| 45 | const result = spawnSync('osascript', [ |
| 46 | '-e', |
| 47 | 'clipboard info', |
| 48 | ], { encoding: 'utf-8', timeout: 1000 }) |
| 49 | |
| 50 | if (result.status !== 0) { |
| 51 | return false |
| 52 | } |
| 53 | |
| 54 | const output = result.stdout || '' |
| 55 | |
| 56 | // Check for image types in clipboard info |
| 57 | return output.includes('«class PNGf»') || |
| 58 | output.includes('TIFF') || |
| 59 | output.includes('«class JPEG»') || |
| 60 | output.includes('public.png') || |
| 61 | output.includes('public.tiff') || |
| 62 | output.includes('public.jpeg') |
| 63 | } catch { |
| 64 | return false |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Read image from clipboard (macOS) |