Mailmate Shell Script failing

I would like some help with my macro.

Execute Shell Script
#!/bin/zsh
	
export PATH=~/bin/:$PATH;
	
emate mailto --from "xxx@gmail.com" --to "xxx@gmail.com" --subject "$KMVAR_VarName" --markup "lorem ipsum" --send-now  	 

emate is a cli package provided by the Mailmate application. The path is fine: if I change the command to emate –help, I get the correct output.

However the above command errors with:

Macro Cancelled
Execute a Shell Script failed with script error: sh: osascript: command not found
Warning: Failed to run osascript opening URL mailto:?from=xxx@gmail.com&to=xxx@gmail.com&subject=xxx&#markup=lorem%20ipsum&send-now=yes).
Macro "Trying" cancelled (while executing Execute Shell Script).

Any ideas?

Maybe because you are using a tilde (~)?

From the action:Execute a Shell Script [Keyboard Maestro Wiki] :

This must be a full path. If the path starts with a tilde (~), then you must first convert it to a full path using the Filter, Expand tilde (~) paths action before the Execute Shell Script action.

Directly reference $HOME instead of ~

#!/bin/zsh
	
export PATH="$HOME/bin/:$PATH";
	
emate mailto --from "xxx@gmail.com" --to "xxx@gmail.com" --subject "$KMVAR_VarName" --markup "lorem ipsum" --send-now

I tried it with the full path as well. Now have attempted using $HOME, but the error is persisting.

I wonder if osascript opening URL mailto is a clue? Is KM seeing mailto in the command and trying to open a mailto: url instead of allowing emate to handle this?

emate (specifically the --send-now flag) likely relies on AppleScript to tell the Mail app to click "Send." Without /usr/bin in your path, the script doesn't know where osascript is.

#!/bin/zsh

# 1. Add standard system paths (/usr/bin is where osascript lives) and your home/bin to the PATH.

export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$HOME/bin:$PATH"

# 2. Run emate

emate mailto 
--from "xxx@gmail.com" 
--to "xxx@gmail.com" 
--subject "$KMVAR_VarName" 
--markup "lorem ipsum" 
--send-now

Awesome! Thank you. Did the trick.

1 Like

No -- that's for when you are passing a path via a KM variable. The ~ will work fine for that line of the shell script, but adds the user's top-level bin directory, which doesn't help here.

You're sorted, but for future reference -- you've edited or deleted the KM ENV_PATH Global variable. By default that is set to

/usr/bin:/bin:/usr/sbin:/sbin

...so your shell script should have found osascript. Check the variable by going to KM's "Settings" then the "Vaariables" pane -- you'll save a lot of future problems if you make sure at least those default paths are present.

1 Like