Inject user path in Plist file when registering on macOS. Fix #233

This commit is contained in:
Federico Terzi 2020-06-10 20:21:18 +02:00
parent 232e80f55a
commit 470f8d6221
2 changed files with 11 additions and 0 deletions

View File

@ -4,6 +4,11 @@
<dict>
<key>Label</key>
<string>com.federicoterzi.espanso</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>{{{PATH}}}</string>
</dict>
<key>ProgramArguments</key>
<array>
<string>{{{espanso_path}}}</string>

View File

@ -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!")