KM Variable use in a shell script

I want to use this variable to send a new email with the subject that is KM variable, but the shell does not read KM variable.

Additional question is how to save a picture in the system clipboard into this email body as part of the script.

new email via shell .kmmacros (22.7 KB)

The shell does read KM variables, but using a different syntax.

Try $KMVAR_MyVariableName instead of %Variable%MyVarName%.

Although there may be some exceptions when quotes are used, and you are using quotes. Give my idea a try and if it still doesn't work we can fix it.

1 Like

"$KMVAR_MyVariableName" will work.

Thank you @noisneil and @Airy

Here is progress:

"$KMVAR_MyVariableName" in subject places $KMVAR_MyVariableName in the subject line (not the actual variable, but its name)

$KMVAR_MyVariableName (w/o quotes) gives an error

From the looks of your post, your variable name is "req__List" not "MyVariableName". :grinning:

You need to use your variable name where we wrote "MyVariableName."

That is understandable. I was just making an example using the variable both of you used.

Please show your macro and we will can tell you what's wrong with it.

here you go:

new email via shell .kmmacros (22.7 KB)

I think the issue relates to the fact that you have nested double quotes inside single quotes.

My method of solving this problem is to keep experimenting until it works. In your case, I can't experiment because I don't have MS Outlook. So we will have to wait for someone with Outlook or with more skill at quotes in Shell.

1 Like

A string surrounded by single quotes will not have the environment variable interpolated.

See: Quoting Strings in the Execute Shell Script action which covers this exact case.

I suggest you use the method described use a combination of strings, some double quoted and some single quoted with something like:

emacsclient -e '(w3m-browse-url "'"$KMVAR_SafariURL"'")'

@peternlewis - what would we do without you !?

Thank you so much!

Here is the solution Peter recommended that works:

osascript -e 'tell application "Microsoft Outlook"' -e 'set newMessage to make new outgoing message with properties {subject:"'"$KMVAR_List"'"}' -e 'make new recipient at newMessage with properties {email address:{name:"DSTUrgentRecords", address:""}}' -e 'open newMessage' -e 'end tell'
1 Like