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 Both sides next revision
action:Execute_a_Shell_Script [2017/09/06 23:43]
peternlewis [How To Use]
action:Execute_a_Shell_Script [2017/09/06 23:51]
peternlewis
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 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 170: Line 166:
 * [[:​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