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 [2018/04/13 16:47]
JMichaelTX [Path in Shell Scripts]
action:Execute_a_Shell_Script [2018/06/05 12:22]
JMichaelTX ADD section on Python
Line 11: Line 11:
  
 ==== Using Keyboard Maestro Variables ==== ==== Using Keyboard Maestro Variables ====
 +
 +=== Most Languages like bash, perl, ruby ===
  
 In your script, use this format: ​ `$KMVAR_[variable_name]` In your script, use this format: ​ `$KMVAR_[variable_name]`
Line 21: Line 23:
  
 {{:​action:​km7-shell-script.png?​nolink|}} {{:​action:​km7-shell-script.png?​nolink|}}
 +
 +=== Python ===
 +
 +Accessing Keyboard Maestro Variables in Python is somewhat different. ​ Here is an example:
 +
 +```python
 +#​!/​usr/​bin/​env python
 +import os
 +print os.environ['​KMVAR_local_DataStr'​].count(os.environ['​KMVAR_local_CharToCount'​])
 +```
 +
 +See the [[#​Forum|Forum]] section below for more Python examples.
 +
 +---
  
 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).
Line 91: Line 107:
     * **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#​Example|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.
action/Execute_a_Shell_Script.txt ยท Last modified: 2023/09/22 04:39 by peternlewis