forked from reujab/wallpaper.rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
macos.rs
44 lines (39 loc) · 1.02 KB
/
macos.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::{get_stdout, run, Mode, Result};
#[cfg(feature = "from_url")]
use crate::download_image;
/// Returns the current wallpaper.
pub fn get() -> Result<String> {
get_stdout(
"osascript",
&[
"-e",
r#"tell application "Finder" to get POSIX path of (get desktop picture as alias)"#,
],
)
}
// Sets the wallpaper from a file.
pub fn set_from_path<P>(path: P) -> Result<()>
where
P: AsRef<Path> + std::fmt::Display,
{
run(
"osascript",
&[
"-e",
&format!(
r#"tell application "System Events" to tell every desktop to set picture to {}"#,
enquote::enquote('"', path),
),
],
)
}
#[cfg(feature = "from_url")]
// Sets the wallpaper from a URL.
pub fn set_from_url(url: &str) -> Result<()> {
let path = download_image(url)?;
set_from_path(&path)
}
/// No-op. Unable to change with AppleScript.
pub fn set_mode(_: Mode) -> Result<()> {
Err("unsupported on macos".into())
}