Skip to content

Instantly share code, notes, and snippets.

@AOx0
Created September 26, 2021 03:23
Show Gist options
  • Save AOx0/b3685dcab8c6a1584c85eb259e0b4a35 to your computer and use it in GitHub Desktop.
Save AOx0/b3685dcab8c6a1584c85eb259e0b4a35 to your computer and use it in GitHub Desktop.
Huh?
use std::io::{BufWriter, Write};
use std::process::{Command, Stdio};
use std::path::Path;
fn main() {
let args = std::env::args().skip(1).collect::<Vec<String>>();
if args.len() == 1 && Path::new(&args[0]).exists() {
let path = Path::new(&args[0]);
let command = format!(r#"
if application "Typora" is running then
tell application "System Events"
tell process "Typora"
set frontmost to true
end tell
tell application "Typora"
open "{0}"
end tell
end tell
else
tell application "Typora" to activate
tell application "System Events"
tell process "Typora"
set frontmost to true
end tell
tell application "Typora"
open "{0}"
end tell
end tell
end if
"#, path.canonicalize().unwrap().display());
let com = Command::new("osascript")
.stdout(Stdio::null())
.stdin(Stdio::piped())
.spawn().unwrap();
let mut outstdin = com.stdin.unwrap();
let mut writer = BufWriter::new(&mut outstdin);
writer.write_all(command.as_bytes()).unwrap();
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment