User Tools

Site Tools


action:Execute_a_Shell_Script

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
action:Execute_a_Shell_Script [2017/09/06 23:43]
peternlewis [How To Use]
action:Execute_a_Shell_Script [2018/04/13 16:48]
JMichaelTX [Path in Shell Scripts]
Line 2: Line 2:
 ====== Execute a Shell Script ====== ====== Execute a Shell Script ======
  
-===== How To Use =====+The //Execute a Shell Script// action executes a specified shell script, either from a file or from the script embedded in the action.
  
-**The Execute a Shell Script action executes a specified shell script, either ​from file or from the script embedded ​in the _Action_ +To execute the script from an external ​file, choose ​the "​Execute Script File" ​in the choices for script location.
-**+
  
-To execute ​the script ​from an external file, choose ​the "​Execute Script File" in the choices for script location.\\+You can choose what input (stdin) to send to the script ​(v8+) as well as where the output should go.
  
 {{:​action:​execute-shell-script.png?​nolink&​693|}} {{:​action:​execute-shell-script.png?​nolink&​693|}}
Line 13: Line 12:
 ==== Using Keyboard Maestro Variables ==== ==== Using Keyboard Maestro Variables ====
  
-Use this format: ​ `$KMVAR_[variable_name]`+In your script, use this format: ​ `$KMVAR_[variable_name]`
  
 where //​[variable‗name]//​ is the name of your Keyboard Maestro Variable, but with spaces in the name replaced with underscores (`‗`). where //​[variable‗name]//​ is the name of your Keyboard Maestro Variable, but with spaces in the name replaced with underscores (`‗`).
  
-For example:  ​"**File Name**" ​would be formated as "**$KMVAR‗File‗Name**".+For example:  ​`File Namewould be formated as `$KMVAR‗File‗Name`.
  
-If your variable already has underscores,​ you can use as is.+If your variable already has underscores,​ you can use it as is.
  
 {{:​action:​km7-shell-script.png?​nolink|}} {{:​action:​km7-shell-script.png?​nolink|}}
  
 Note that you can only read these environment variables. ​ You cannot write to them (or more accurately, you can write to them but that will not change the Keyboard Maestro variables that they were created from). Note that you can only read these environment variables. ​ You cannot write to them (or more accurately, you can write to them but that will not change the Keyboard Maestro variables that they were created from).
 +
 ==== Passing Paths in Variables ==== ==== Passing Paths in Variables ====
  
Line 31: Line 31:
 ``` ```
  
-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 [[action: ​Filter_Variable  ​| Filter ​Variable, Expand tilde (~) paths]] Action BEFORE the Execute Shell Script Action. +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 [[action:Filter ​| Filter, Expand tilde (~) paths]] Action BEFORE the Execute Shell Script Action.
- +
-For more info, see an excellent, detailed discussion of [[https://​forum.keyboardmaestro.com/​t/​png-metadata-comment/​6375/​29?​u=jmichaeltx | How To Quote Paths by @ccstone]]. +
  
 +For more info, see an excellent, detailed discussion of [[https://​forum.keyboardmaestro.com/​t/​png-metadata-comment/​6375/​29| How To Quote Paths by @ccstone]].
  
 ==== Action Gear ==== ==== Action Gear ====
Line 70: Line 68:
 Proper quoting of strings in a Shell Script is often a challenge. Proper quoting of strings in a Shell Script is often a challenge.
  
-For a discussion on how to quote a string, see this [[https://​forum.keyboardmaestro.com/​t/​having-trouble-with-quotes-and-shell-variables/​6236/​9?​u=jmichaeltx ​| Keyboard Maestro Forum post by @PeterNLewis]].+For a discussion on how to quote a string, see this [[https://​forum.keyboardmaestro.com/​t/​having-trouble-with-quotes-and-shell-variables/​6236/​9 | Keyboard Maestro Forum post by @PeterNLewis]].
  
  
Line 93: Line 91:
     * **Set `ENV_PATH`** (the Keyboard Maestro Path Variable) **prior to the Execute Shell Script Action.**     * **Set `ENV_PATH`** (the Keyboard Maestro Path Variable) **prior to the Execute Shell Script Action.**
       * The path defined in this Variable will automatically apply to every Execute Shell Script, without need for further reference. ​ It will work just like your `$PATH` works in the Terminal app.       * The path defined in this Variable will automatically apply to every Execute Shell Script, without need for further reference. ​ It will work just like your `$PATH` works in the Terminal app.
-      * You can set this Variable manually in the [[manual:​Windows#​Preferences_Variables_Pane|Variable Preferences ​Pane]] of the _Keyboard Maestro App Preferences_.+      * You can set this Variable manually in the [[manual:​Windows#​Example|Variable Preferences ​Panel]] of the _Keyboard Maestro App Preferences_.
       * Once the `ENV_PATH` Variable is set, it will remain in your Keyboard Maestro Variable set (until/​unless you delete it), available to every Execute Shell Script Action that you might use in the future. ​ So you don't need to set it in every Macro.       * Once the `ENV_PATH` Variable is set, it will remain in your Keyboard Maestro Variable set (until/​unless you delete it), available to every Execute Shell Script Action that you might use in the future. ​ So you don't need to set it in every Macro.
       * If your tool requires other environment variables to be set you can set them as well by creating an appropriate Keyboard Maestro variable with `ENV_` at the front.       * If your tool requires other environment variables to be set you can set them as well by creating an appropriate Keyboard Maestro variable with `ENV_` at the front.
Line 106: Line 104:
 Of course, if you have tools or files you installed elsewhere, then you would need to include the path to those in this path statement, IF you plan to use any of those tools/files in a Execute Shell Script Action. Of course, if you have tools or files you installed elsewhere, then you would need to include the path to those in this path statement, IF you plan to use any of those tools/files in a Execute Shell Script Action.
  
-You can create the `ENV_PATH` Variable one time using the [[manual:​Windows#​Preferences_Variables_Pane|Variable Preferences Pane]] of the _Keyboard Maestro Preferences_.+You can create the `ENV_PATH` Variable one time using the [[manual:​Windows#​Example|Variable Preferences Pane]] of the _Keyboard Maestro Preferences_.
   * Add a variable named `ENV_PATH` and set its value.   * Add a variable named `ENV_PATH` and set its value.
   * Once set, it will remain unchanged until you change or delete it.   * Once set, it will remain unchanged until you change or delete it.
Line 114: Line 112:
 For a good discussion about this see:  ​ For a good discussion about this see:  ​
   * [KM can"t find shell commands ](https://​forum.keyboardmaestro.com/​t/​km-cant-find-shell-commands/​5430)   * [KM can"t find shell commands ](https://​forum.keyboardmaestro.com/​t/​km-cant-find-shell-commands/​5430)
-  * [[https://​forum.keyboardmaestro.com/​t/​png-metadata-comment/​6375/​16?​u=jmichaeltx ​| Post by @ccstone]]+  * [[https://​forum.keyboardmaestro.com/​t/​png-metadata-comment/​6375/​16| Post by @ccstone]]
  
---- 
 ===== Execute Script From Other Apps ===== ===== Execute Script From Other Apps =====
  
Line 158: Line 155:
 osascript -e "​$theAppleScript";​ osascript -e "​$theAppleScript";​
 </​code>​ </​code>​
-===== See Also ===== 
  
-----+===== See Also =====
  
 === Actions === === Actions ===
Line 167: Line 163:
 * [[action:​Execute an Automator Workflow|Execute an Automator Workflow]] * [[action:​Execute an Automator Workflow|Execute an Automator Workflow]]
 * [[action:​Execute a JavaScript For Automation|Execute a JavaScript For Automation]] * [[action:​Execute a JavaScript For Automation|Execute a JavaScript For Automation]]
-* [[action:​Filter ​Variable|Filter Variable with Expand Tilde In Path]]+* [[action:​Filter|Filter Variable with Expand Tilde In Path]]
 * [[:​Actions|See all Actions]] * [[:​Actions|See all Actions]]
  
----- 
 ==== Forum ==== ==== Forum ====
  
 +- [[https://​forum.keyboardmaestro.com/​t/​png-metadata-comment/​6375/​29|PNG Metadata "​Comment"​]]
 +- [[https://​forum.keyboardmaestro.com/​t/​having-trouble-with-quotes-and-shell-variables/​6236/​9|Having trouble with quotes and shell variables]]
 +- [[https://​forum.keyboardmaestro.com/​t/​km-cant-find-shell-commands/​5430|KM can't find shell commands]]
 - [[https://​forum.keyboardmaestro.com/​t/​tag-selected-files/​220/​11|Tag Selected Files]] - [[https://​forum.keyboardmaestro.com/​t/​tag-selected-files/​220/​11|Tag Selected Files]]
 - [[https://​forum.keyboardmaestro.com/​t/​processing-selected-files-in-a-python-script/​275|Processing selected files in a python script]] - [[https://​forum.keyboardmaestro.com/​t/​processing-selected-files-in-a-python-script/​275|Processing selected files in a python script]]
Line 190: Line 188:
  
 - [[https://​forum.keyboardmaestro.com/​tags/​shellscript|Keyboard Maestro Forum topics about Shell Script]] - [[https://​forum.keyboardmaestro.com/​tags/​shellscript|Keyboard Maestro Forum topics about Shell Script]]
- 
---- 
  
 **Keywords:​** Quote String, Bash, Shell Scripting **Keywords:​** Quote String, Bash, Shell Scripting
action/Execute_a_Shell_Script.txt · Last modified: 2023/09/22 04:39 by peternlewis