MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / read_image_macos

Function read_image_macos

crates/opencode-tui/src/ui/clipboard.rs:203–241  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

201}
202
203fn read_image_macos() -> anyhow::Result<String> {
204 let temp_path = std::env::temp_dir().join("opencode_clipboard_image.png");
205 let temp_str = temp_path.to_str().context("temp path is not valid UTF-8")?;
206
207 let script = format!(
208 concat!(
209 "set imageData to the clipboard as «class PNGf»\n",
210 "set filePath to POSIX file \"{}\"\n",
211 "set fileRef to open for access filePath with write permission\n",
212 "set eof fileRef to 0\n",
213 "write imageData to fileRef\n",
214 "close access fileRef"
215 ),
216 temp_str
217 );
218
219 let output = Command::new("osascript")
220 .arg("-e")
221 .arg(&script)
222 .output()
223 .context("failed to execute osascript for clipboard image")?;
224
225 if !output.status.success() {
226 anyhow::bail!(
227 "osascript clipboard image read failed with status {}",
228 output.status
229 );
230 }
231
232 let png_bytes =
233 std::fs::read(&temp_path).context("failed to read clipboard image temp file")?;
234 let _ = std::fs::remove_file(&temp_path);
235
236 if png_bytes.is_empty() {
237 anyhow::bail!("clipboard image temp file was empty");
238 }
239
240 Ok(STANDARD.encode(&png_bytes))
241}
242
243fn read_image_windows() -> anyhow::Result<String> {
244 let ps_script = concat!(

Callers 1

Calls 4

newFunction · 0.85
outputMethod · 0.80
is_emptyMethod · 0.80
successMethod · 0.45

Tested by

no test coverage detected