**This is an old revision of the document!**
The Execute a Shell Script action executes a specified shell script, either from a file or text. For example, pbpaste | pbcopy.
The results of a shell script can be:
- Ignored.
- Displayed in a floating window.
- Displayed briefly in a Notification.
- Typed in to the current selection.
- Pasted in to the current selection.
- Saved to a variable.
- Saved to the system or a Named Clipboard.
- Asynchronously ignored — the action runs while the macro continues on.
For example, you could have a shell script date display briefly in the Notification Center every hour, or use a hot key to type the results directly into your text editor.
You can also use the clipboard by piping from pbpaste and to pbcopy.
The Action (gear) menu includes the following options:
- Trim Results — removes white space from the start and end of the scripts results.
- Include Errors — include stdout and stderr results from the script.
Shell scripts are executed in the background and can access variables by using environment variables (for example, the “Variable Name” Keyboard Maestro variable can be accessed as “KMVARVariableName).
Shells are executed in non-interactive mode (see the INVOCATION section of the base man page). As such none of your profile scripts (like ~/.profile) will be executed. This means that custom environment variable settings will not be applied, in particular any settings for your PATH environment variable, and any settings for tool-specific environment variables like PERL5LIB). You can set these by creating a variable with “ENV” at the start (eg ENVPATH or ENV_ PERL5LIB) and settings its value appropriately.
See also these forum topics:
