diff --git a/src/pasteboard/mod.rs b/src/pasteboard/mod.rs index 9765811b..4338fc26 100644 --- a/src/pasteboard/mod.rs +++ b/src/pasteboard/mod.rs @@ -111,4 +111,31 @@ impl Pasteboard { Ok(urls) } } + + /// Write a list of path to the pasteboard + pub fn set_files(&self, paths: &[&Path]) -> Result<(), Box> { + unsafe { + let urls: Vec = paths + .iter() + .map(|p| { + let url = format!("file://{}", p.display()); + NSURL::with_str(&url) + }) + .collect(); + let url_arr = NSArray::new(&urls); + + let _: id = msg_send![&*self.0, clearContents]; + let succ: bool = msg_send![&*self.0, writeObjects: &*url_arr]; + + if succ { + Ok(()) + } else { + return Err(Box::new(Error { + code: 666, + domain: "com.cacao-rs.pasteboard".to_string(), + description: "Pasteboard server set urls fail.".to_string() + })); + } + } + } }