From 470f8d62217b519faa7aeb7dd6e9e7444b97c8f4 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Wed, 10 Jun 2020 20:21:18 +0200 Subject: [PATCH] Inject user path in Plist file when registering on macOS. Fix #233 --- src/res/mac/com.federicoterzi.espanso.plist | 5 +++++ src/sysdaemon.rs | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/res/mac/com.federicoterzi.espanso.plist b/src/res/mac/com.federicoterzi.espanso.plist index 0728b20..e537367 100644 --- a/src/res/mac/com.federicoterzi.espanso.plist +++ b/src/res/mac/com.federicoterzi.espanso.plist @@ -4,6 +4,11 @@ Label com.federicoterzi.espanso + EnvironmentVariables + + PATH + {{{PATH}}} + ProgramArguments {{{espanso_path}}} diff --git a/src/sysdaemon.rs b/src/sysdaemon.rs index 4d4c055..de54983 100644 --- a/src/sysdaemon.rs +++ b/src/sysdaemon.rs @@ -61,6 +61,12 @@ pub fn register(_config_set: ConfigSet) { espanso_path.to_str().unwrap_or_default(), ); + // Copy the user PATH variable and inject it in the Plist file so that + // it gets loaded by Launchd. + // To see why this is necessary: https://github.com/federico-terzi/espanso/issues/233 + let user_path = std::env::var("PATH").unwrap_or("".to_owned()); + let plist_content = plist_content.replace("{{{PATH}}}", &user_path); + std::fs::write(plist_file.clone(), plist_content).expect("Unable to write plist file"); println!("Entry created correctly!")