User Tools

Site Tools


Variables

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
Variables [2017/09/04 00:05]
peternlewis [Setting Variables]
Variables [2017/09/26 01:17]
peternlewis removed
Line 2: Line 2:
  
 Keyboard Maestro [[manual:​Variables|variables]] are used much like variables in any scripting or macro language. ​ They provide for the storage of data (only plain text, no styles) as determined by you, the Keyboard Maestro user.  ​ Keyboard Maestro [[manual:​Variables|variables]] are used much like variables in any scripting or macro language. ​ They provide for the storage of data (only plain text, no styles) as determined by you, the Keyboard Maestro user.  ​
 +
 +===== ❗️ NOTICE =====
 +**This page is superseded by this page:  [[manual:​Variables|Variables (in the Manual Segment).]]**
 +
 +---
  
 ===== Key Facts about Variables ===== ===== Key Facts about Variables =====
Line 60: Line 65:
 You can also use a short form of just //%Variable Name%// to include variables as long as the variable exists and has a value and there is no corresponding text token, although generally it is better and clearer to use the longer form //​%Variable%Variable Name%//. You can also use a short form of just //%Variable Name%// to include variables as long as the variable exists and has a value and there is no corresponding text token, although generally it is better and clearer to use the longer form //​%Variable%Variable Name%//.
  
 +You can also access variables in a token field numerically using the [[token:​Calculate|%Calculate%]] token. ​ **It is important to note that calculations can contain only numeric values**. ​ When you use the [[token:​Calculate|%Calculate%]] token to reference a variable or variable array element, it will convert the element to a number.
  
-==== Variable Arrays ​====+==== Variables in Calculations ​====
  
-Variables can contain an array of comma separated **numbers**,​ like the image size (123,​456) ​or window frame (100,​120,​600,​550). In calculation field, you can refer to these using a normal (1-based) index notation, like Variable[2]So you can use ClipboardImageSize[1] and ClipboardImageSize[2]. +Variables can be used in calculations if their value holds a number ​or a numeric expression that can be evaluated ​Variables are used *unadornedin calculations,​ for example `My Variable ​7`.  ​If a variable ​contains a sequence of comma-separated numbers, it can be accessed as an arrayfor example `My Variable[7]`, or using dot notationfor example ​`My Variable.x`.  See the [[manual:​Calculations#​Variable_Array_Access|Calculations]] user manual section for more information on calculations and using variables in numeric fields.
- +
-**It is important to note that variable arrays can contain only numeric values**.  ​When you use the [[token:​Calculate|%Calculate%]] function to reference ​a variable ​array element, it will convert the element to a number. ​ Soin effect, you can only use variable arrays to store/​reference numbers. +
- +
-For example, suppose the variable ​`MyArrayhas this value: `10,05,00,12`. In any Keyboard Maestro Action where you would like to use the array element ​`%Calculate%MyArray[2]%`, it will return "​5"​ because it has evaluated it as number, not the actual string of the element "​05"​.+
  
 ===== Using Variables in Scripts ===== ===== Using Variables in Scripts =====
Line 88: Line 90:
 Variables with names that start or end with “Password” or “PW” are considered passwords – their values will not be stored (except in memory) and they cannot be read directly by shell scripts or AppleScripts,​ though their consequences can easily be extracted, eg with the Set Clipboard to Text action. The Prompt For User Input dialog will display such variables in a password field. Variables with names that start or end with “Password” or “PW” are considered passwords – their values will not be stored (except in memory) and they cannot be read directly by shell scripts or AppleScripts,​ though their consequences can easily be extracted, eg with the Set Clipboard to Text action. The Prompt For User Input dialog will display such variables in a password field.
  
-===== See Also =====+You should set their values immediately after you are done with the password to reduce any change of erroneous access.
  
-----+===== Local Variables ===== 
 + 
 +Variables with names that start with “Local ” (“Local ” with a space, then the rest of the variable name, eg “Local Count”) are considered local (v8+) to a specific instance of a specific macro. Each time the macro is run, they will start empty and no other macro will see or be able to change values. 
 +===== Instance Variables ===== 
 + 
 +Variables with names that start with “Instance ” (“Instance ” with a space, then the rest of the variable name, eg “Instance Count”) are considered local (v8+) to a specific execution sequence. Each time the macro is run, they will start empty but their value can be seen and changed by other macros within the same execution sequence (for example, if you execute a macro using the Execute Macro action, that macro can see and change the instance variable). Since two instances of a macro can be running at the same time, this is useful to ensure they each have their own version of the variable. 
 + 
 +===== See Also =====
  
 === Actions === === Actions ===
Line 97: Line 106:
 * [[action:​Set Variable to Text|Set Variable to Text]] * [[action:​Set Variable to Text|Set Variable to Text]]
 * [[:​Actions|See all Actions]] * [[:​Actions|See all Actions]]
- 
----- 
  
 ==== Forum ==== ==== Forum ====