This shows you the differences between two versions of the page.
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:48] JMichaelTX [Path in Shell Scripts] |
action:Execute_a_Shell_Script [2019/04/25 05:11] peternlewis UTF-8 and Non-ASCII Characters |
||
---|---|---|---|
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 16: | Line 18: | ||
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 Name` would be formatted as `$KMVAR‗File‗Name`. |
If your variable already has underscores, you can use it 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|}} | ||
+ | |||
+ | === 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 34: | Line 50: | ||
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]]. | 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]]. | ||
+ | |||
+ | ==== UTF-8 and Non-ASCII Characters ==== | ||
+ | |||
+ | If you are dealing with non-ASCII characters, you probably want to set the `LC_ALL` environment variable to UTF8, which you can do by setting the Keyboard Maestro variable `ENV_LC_ALL` to “en_US.UTF-8”. | ||
==== Action Gear ==== | ==== Action Gear ==== |