Skip to content

Commit

Permalink
feat(macos): implement wallpaper setting
Browse files Browse the repository at this point in the history
  • Loading branch information
InioX committed Dec 3, 2023
1 parent 4e2f0f1 commit 43c9161
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ colorsys = "0.6.7"
prettytable-rs = "0.10.0"
serde_json = "1.0.107"
update-informer = "1.1.0"
enquote = "1.1.0"

[workspace]
members = ["material-color-utilities-rs"]
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ Matugen is a cross-platform tool that generates a colorscheme either from an ima
- Linux
- MacOS
- NetBSD
> [!WARNING]
> Matugen does not support setting the wallpaper on MacOS for now.

<h2>
<sub>
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ fn main() -> Result<(), Report> {
#[cfg(target_os = "windows")]
wallpaper::windows::set(&path)?;

#[cfg(target_os = "macos")]
wallpaper::macos::set(&path)?;

#[cfg(any(target_os = "linux", target_os = "netbsd"))]
wallpaper::unix::set(
path,
Expand Down
15 changes: 15 additions & 0 deletions src/wallpaper/macos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use std::process::Command;
use color_eyre::Report;

#[cfg(target_os = "macos")]
pub fn set(path: &str) -> Result<(), Report> {
// Generate the Applescript string
let cmd = &format!(
r#"tell app "finder" to set desktop picture to POSIX file {}"#,
enquote::enquote('"', path),
);
// Run it using osascript
Command::new("osascript").args(&["-e", cmd]).output()?;

Ok(())
}
3 changes: 3 additions & 0 deletions src/wallpaper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ pub mod unix;

#[cfg(target_os = "windows")]
pub mod windows;

#[cfg(target_os = "macos")]
pub mod macos;

0 comments on commit 43c9161

Please sign in to comment.